public void DeleteProductInvoiceDetail(List <ProductInvoiceDetail> list) { foreach (var item in list) { var listlog = GetAllUsingServiceLog().Where(x => x.ServiceInvoiceDetailId == item.Id).Select(x => x.Id).ToList(); var listlogReminder = GetAllLogServiceRemminder().Where(x => x.ProductInvoiceDetailId == item.Id).Select(x => x.Id).ToList(); foreach (var logId in listlog) { var listlogDetail = GetAllUsingServiceLogDetail().Where(x => x.UsingServiceId == logId).Select(x => x.Id).ToList(); foreach (var logDetailId in listlogDetail) { UsingServiceLogDetail deleteUsingServiceLogDetail = GetUsingServiceLogDetailById(logDetailId); Context.UsingServiceLogDetail.Remove(deleteUsingServiceLogDetail); Context.Entry(deleteUsingServiceLogDetail).State = EntityState.Deleted; } UsingServiceLog deleteUsingServiceLog = GetUsingServiceLogById(logId); Context.UsingServiceLog.Remove(deleteUsingServiceLog); Context.Entry(deleteUsingServiceLog).State = EntityState.Deleted; } foreach (var reminder in listlogReminder) { LogServiceRemminder deleteLogServiceRemminder = GetLogServiceRemminderById(reminder); Context.LogServiceRemminder.Remove(deleteLogServiceRemminder); Context.Entry(deleteLogServiceRemminder).State = EntityState.Deleted; } ProductInvoiceDetail deletedProductInvoiceDetail = GetProductInvoiceDetailById(item.Id); Context.ProductInvoiceDetail.Remove(deletedProductInvoiceDetail); Context.Entry(deletedProductInvoiceDetail).State = EntityState.Deleted; } Context.SaveChanges(); }
public ActionResult Update(int StaffId, string check, string Status, string type) { string[] arrUsingServiceLogId = check.Split(','); for (int i = 0; i < arrUsingServiceLogId.Count(); i++) { if (arrUsingServiceLogId[i] != "") { var log = new UsingServiceLogDetail(); log.StaffId = StaffId; log.CreatedDate = DateTime.Now; log.CreatedUserId = WebSecurity.CurrentUserId; log.ModifiedDate = DateTime.Now; log.ModifiedUserId = WebSecurity.CurrentUserId; log.AssignedUserId = WebSecurity.CurrentUserId; log.IsDeleted = false; log.Status = Status; log.Type = type; log.UsingServiceId = int.Parse(arrUsingServiceLogId[i], CultureInfo.InvariantCulture); var usingLog = usingServiceLogRepository.GetUsingServiceLogById(int.Parse(arrUsingServiceLogId[i], CultureInfo.InvariantCulture)); if (type == "usedservice") { if (usingLog.QuantityUsed < usingLog.Quantity) { usingLog.QuantityUsed = usingLog.QuantityUsed + 1; usingServiceLogRepository.UpdateUsingServiceLog(usingLog); usingServiceLogDetailRepository.InsertUsingServiceLogDetail(log); } else { return(Content("error")); } } else { usingServiceLogDetailRepository.InsertUsingServiceLogDetail(log); } } } return(Content("success")); }