public async Task <ActionResult> DeleteConfirmed(int id, int?page, int?idItemType, int?pageSize) { Item item = await this.serviceItem.FindAsync(id); IServiceCustumerOrderItem serviceCustumerOrderItem = DependencyResolver.Current.GetService <ServiceCustumerOrderItem>(); IServiceSupplierOffer serviceSupplierOffer = DependencyResolver.Current.GetService <ServiceSupplierOffer>(); if (!serviceSupplierOffer.HasRelation(item) && !serviceCustumerOrderItem.HasRelation(item)) { var listValuesToDelete = item.AttributeValues; int count = item.AttributeValues.Count(); for (int i = 0; i < count; i++) { this.serviceAttributeValue.Delete(item.AttributeValues[0]); } this.unitOfWorkAsync.SaveChanges(); this.serviceItem.Delete(item); await this.unitOfWorkAsync.SaveChangesAsync(); } return(RedirectToAction("Index", new { page = this.ViewBag.page, idItemType = this.ViewBag.idItemType, pageSiz = this.ViewBag.pageSize })); }
// GET: Admin/Item/Delete/5 public async Task <ActionResult> Delete(int?id, int?page, int?idItemType, int?pageSize) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Item item = await this.serviceItem.FindAsync(id); if (item == null) { return(HttpNotFound()); } IServiceCustumerOrderItem serviceCustumerOrderItem = DependencyResolver.Current.GetService <ServiceCustumerOrderItem>(); IServiceSupplierOffer serviceSupplierOffer = DependencyResolver.Current.GetService <ServiceSupplierOffer>(); bool hasRelationOffers = serviceSupplierOffer.HasRelation(item);; bool hasRelationOrders = serviceCustumerOrderItem.HasRelation(item); this.ViewBag.hasRelationOffers = hasRelationOffers; this.ViewBag.hasRelationOrders = hasRelationOrders; this.ViewBag.page = page; this.ViewBag.idItemType = idItemType; this.ViewBag.pageSize = pageSize; return(View(item)); }