コード例 #1
0
        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 ImportDetail Delete(int id)
 {
     return(_importDetailRepository.Delete(id));
 }