public ActionResult ChangeAgreementItemPeriods(long id, long itemId, long serviceId, int quantity) { var agreement = DataContext.LeadAgreements.FirstOrDefault(o => o.Id == id); if (agreement == null) { return Json(new { success = false, msg = "Договор не найден" }); } if (agreement.Status != (short)LeadAgreementStatus.Negotiation) { return Json(new { success = false, msg = "Нельзя редактировать позиции договора в этом статусе" }); } // Ищем позицию var serviceType = serviceId == 0 ? agreement.Project.ServiceTypes.First() : agreement.Project.ServiceTypes.First(s => s.Id == serviceId); LeadAgreementService agreementService; if (serviceId == 0 && itemId == 0) { agreementService = new LeadAgreementService() { LeadAgreement = agreement, Price = serviceType.Price, Period = quantity, ServiceType = serviceType }; agreement.LeadAgreementServices.Add(agreementService); } else { agreementService = agreement.LeadAgreementServices.FirstOrDefault(oi => oi.Id == itemId); if (agreementService == null) { return Json(new { success = false, msg = "Такая позиция не найдена" }); } // Изменяем продукт if (serviceType == null) { return Json(new { success = false, msg = "Новый тип услуги не найден" }); } agreementService.Period = quantity; agreementService.DateModified = DateTime.Now; } // Пытаемся сохранить try { DataContext.SubmitChanges(); } catch (Exception e) { return Json(new { success = false, msg = e.Message }); } // Отдаем успешный результат return Json(new { success = true, id = agreementService.Id, serviceId = agreementService.ServiceTypeId, }); }
private void detach_LeadAgreementServices(LeadAgreementService entity) { this.SendPropertyChanging(); entity.LeadAgreement = null; }
public ActionResult ChangeAgreementItemService(long id, long itemId, long serviceId, long newId) { var agreement = DataContext.LeadAgreements.FirstOrDefault(o => o.Id == id); if (agreement == null) { return Json(new { success = false, msg = "Договор не найден" }); } if (agreement.Status != (short)LeadAgreementStatus.Negotiation) { return Json(new { success = false, msg = "Нельзя редактировать позиции договора в этом статусе" }); } // Ищем позицию var serviceType = agreement.Project.ServiceTypes.First(s => s.Id == newId); var totalPeriods = serviceType.ComputeTotalPeriods(agreement); LeadAgreementService agreementService; if (serviceId == 0 && itemId == 0) { agreementService = new LeadAgreementService() { LeadAgreement = agreement, Price = serviceType.Price, Period = totalPeriods, ServiceType = serviceType }; agreement.LeadAgreementServices.Add(agreementService); } else { agreementService = agreement.LeadAgreementServices.FirstOrDefault(oi => oi.Id == itemId); if (agreementService == null) { return Json(new { success = false, msg = "Такая позиция не найдена" }); } // Изменяем продукт if (serviceType == null) { return Json(new { success = false, msg = "Новый тип услуги не найден" }); } agreementService.ServiceType.LeadAgreementServices.Remove(agreementService); serviceType.LeadAgreementServices.Add(agreementService); agreementService.DateModified = DateTime.Now; } // Пытаемся сохранить try { DataContext.SubmitChanges(); } catch (Exception e) { return Json(new { success = false, msg = e.Message }); } // Отдаем успешный результат return Json(new { success = true, id = agreementService.Id, serviceId = agreementService.ServiceTypeId, price = agreementService.Price.ToString("0.00"), period = ((LeadServicePeriods)agreementService.ServiceType.PeriodType).GetEnumMemberName(), periods = totalPeriods }); }
private void attach_LeadAgreementServices(LeadAgreementService entity) { this.SendPropertyChanging(); entity.ServiceType = this; }