Добрый день
Я пытаюсь жестко удалить мягко удаленные записи, у меня есть метод Task PermanantlyDeleteDeal(GetDealInput input)
Когда я вызываю метод, он не входит.
Поскольку шаблон 0.9.6 не сложно удалить, сейчас я использую класс Database>DataContext.cs
для выполнения жесткого удаления
Вот мой класс DataContext
public class DataContext : DbContext
{
public virtual DbSet<Deal> Deal{ get; set; }
public DataContext()
: base("Default")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
}}
Вот функция на javaScript, которая вызывает метод
function DeleteLead(btnCaller) {
abp.message.confirm('Lead will be deleted.', 'Are you sure?', function (isConfirmed) {
if (isConfirmed) {
var button = $(btnCaller);
var proposalId = button.data('content');
var proposalObject = Object({
Id: proposalId
});
abp.ui.setBusy();
_leadService.permanantlyDeleteLead(proposalObject).done(function (result) {
abp.notify.success('Successfully deleted a proposal', 'Quotation deleted');
Refresh();
}).always(function () {
abp.ui.clearBusy();
});
}
});
}
Вот постоянный комментарий об удалении
public async Task PermanantlyDeleteDeal(GetDealInput input)
{
UserFriendlyException ufex = null;
try
{
DataContext db = new DataContext();
using (Repository.Repository<Deal> repo = new Repository.Repository<Deal>(db))
{
using (Repository.Repository<DealComment> dealCommentRepo = new Repository.Repository<DealComment>(db))
{
using (Repository.Repository<Proposal> proposalRepo = new Repository.Repository<Proposal>(db))
{
using (Repository.Repository<Quotation> quotationRepo = new Repository.Repository<Quotation>(db))
{
Deal deal = repo.GetById(input.Id);
List<DealComment> listOfDealComments = dealCommentRepo.GetAll().Where(dc => dc.DealId == deal.Id).ToList();
List<Proposal> listOfProposals = proposalRepo.GetAll().Where(x => x.DealId == deal.Id).ToList();
List<Quotation> listOfQuotations = quotationRepo.GetAll().Where(x => x.DealId == deal.Id).ToList();
if (listOfProposals.Count > 0 || listOfQuotations.Count > 0)
{
string message = string.Empty;
message += listOfProposals.Count > 0 ? "Cannot delete deal, this deal is linked to:\nProposals\n" : "Cannot delete deal, this deal is linked to:\n";
foreach (var item in listOfProposals)
{
message += $"- {item.Application}\n";
}
message += listOfQuotations.Count > 0 ? "Quotations:\n" : "";
foreach (var item in listOfQuotations)
{
message += $"- {item.Description}\n";
}
ufex = new UserFriendlyException("Ooops! There is a problem.", $"{message}");
throw ufex;
}
else
{
foreach (var item in listOfDealComments)
{
dealCommentRepo.Delete(item);
dealCommentRepo.SaveChanges();
}
if (deal != null)
{
repo.Delete(deal);
repo.SaveChanges();
}
}
}
}
}
}
}
catch
{
if(ufex != null)
throw ufex;
else
throw new UserFriendlyException("Ooops! There is a problem.",$"Deal with Id[{input.Id}] could not be deleted.");
}
}
Abp.Boilerplate 0,9,6
Abp.EntityFramework 0.9.6