コード例 #1
0
		private void detach_LeadAgreementChangements(LeadAgreementChangement entity)
		{
			this.SendPropertyChanging();
			entity.User = null;
		}
コード例 #2
0
        public ActionResult UpdateAgreementInfo(LeadAgreement model, string comments)
        {
            var projects = CurrentUser.IsAdmin() ? DataContext.Projects.Select(p => p.Id) : CurrentUser.ProjectUsers.Select(p => p.ProjectId);
            var agreement = DataContext.LeadAgreements.FirstOrDefault(a => a.Id == model.Id && projects.Contains(a.ProjectId));
            if (agreement == null)
            {
                ShowError("Такой договор не найден");
                return RedirectToAction("Index");
            }

            // Валидируем номер договора - он должен быть уникальным
            var existed =
                agreement.Project.LeadAgreements.Any(
                    a => a.Number.ToLower() == model.Number.ToLower() && a.Id != agreement.Id);
            if (existed)
            {
                ShowError("Договор с таким номером уже есть в системе");
                return RedirectToAction("Info", new {id = agreement.Id});
            }

            // Изменение
            var changement = new LeadAgreementChangement()
            {
                Comments = comments,
                User = CurrentUser,
                LeadAgreement = agreement,
                DateCreated = DateTime.Now
            };
            if (model.Number != agreement.Number)
            {
                changement.LeadAgreementChangementValues.Add(new LeadAgreementChangementValue()
                {
                    LeadAgreementChangement = changement,
                    OldValue = agreement.Number,
                    NewValue = model.Number,
                    PropertyName = "Номер"
                });
                agreement.Number = model.Number;
            }
            if (model.Date != agreement.Date)
            {
                changement.LeadAgreementChangementValues.Add(new LeadAgreementChangementValue()
                {
                    LeadAgreementChangement = changement,
                    OldValue = agreement.Date.FormatDate(),
                    NewValue = model.Date.FormatDate(),
                    PropertyName = "Дата заключения"
                });
                agreement.Date = model.Date;
            }
            if (model.EndDate != agreement.EndDate)
            {
                changement.LeadAgreementChangementValues.Add(new LeadAgreementChangementValue()
                {
                    LeadAgreementChangement = changement,
                    OldValue = agreement.EndDate.FormatDate(),
                    NewValue = model.EndDate.FormatDate(),
                    PropertyName = "Дата завершения действия"
                });
                agreement.EndDate = model.EndDate;
            }
            if (model.EndDate != agreement.EndDate)
            {
                changement.LeadAgreementChangementValues.Add(new LeadAgreementChangementValue()
                {
                    LeadAgreementChangement = changement,
                    OldValue = agreement.EndDate.FormatDate(),
                    NewValue = model.EndDate.FormatDate(),
                    PropertyName = "Дата завершения действия"
                });
                agreement.EndDate = model.EndDate;
            }
            if (model.Title != agreement.Title)
            {
                changement.LeadAgreementChangementValues.Add(new LeadAgreementChangementValue()
                {
                    LeadAgreementChangement = changement,
                    OldValue = agreement.Title,
                    NewValue = model.Title,
                    PropertyName = "Название"
                });
                agreement.Title = model.Title;
            }
            if (model.Description != agreement.Description)
            {
                changement.LeadAgreementChangementValues.Add(new LeadAgreementChangementValue()
                {
                    LeadAgreementChangement = changement,
                    OldValue = agreement.Description,
                    NewValue = model.Description,
                    PropertyName = "Описание"
                });
                agreement.Description = model.Description;
            }
            if (model.Status != agreement.Status)
            {
                changement.LeadAgreementChangementValues.Add(new LeadAgreementChangementValue()
                {
                    LeadAgreementChangement = changement,
                    OldValue = ((LeadAgreementStatus)agreement.Status).GetEnumMemberName(),
                    NewValue = ((LeadAgreementStatus)model.Status).GetEnumMemberName(),
                    PropertyName = "Статус"
                });
                agreement.Status = model.Status;
            }
            if (changement.LeadAgreementChangementValues.Count > 0)
            {
                agreement.LeadAgreementChangements.Add(changement);
                agreement.DateModified = DateTime.Now;
                DataContext.SubmitChanges();
            }

            ShowSuccess(string.Format("Договор №{0} был успешно сохранен", agreement.Number));

            return RedirectToAction("Info", new {id = agreement.Id});
        }
コード例 #3
0
		private void attach_LeadAgreementChangements(LeadAgreementChangement entity)
		{
			this.SendPropertyChanging();
			entity.LeadAgreement = this;
		}