public async Task <JsonResult> DeleteImport(int id)
        {
            try
            {
                var listdetailId = _importDetailRepository.All.Where(x => x.IdImport == id).ToList();
                foreach (var i in listdetailId)
                {
                    _importDetailRepository.Delete(i);
                    var sp = _productRepository.All.ToList().Single(n => n.Id == i.IdProduct);
                    sp.BasketCount -= i.Amount.GetValueOrDefault();
                    _productRepository.UpdateAsync(sp);
                }

                await _productRepository.SaveAsync(requestContext : RequestContext);

                await _importDetailRepository.SaveAsync(RequestContext);

                _importRepository.Delete(id);
                await _importRepository.SaveAsync(RequestContext);

                return(Json(new
                {
                    isDeleted = true,
                    html = Helper
                           .RenderRazorViewToString(this, "_ViewListImports", await _importRepository.All.ToListAsync())
                }));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return(Json(new
                {
                    isDeleted = false,
                    html = Helper
                           .RenderRazorViewToString(this, "_ViewListImports", await _importRepository.All.ToListAsync())
                }));
            }
        }
示例#2
0
 public Import Delete(int id)
 {
     return(_importRepository.Delete(id));
 }