public int Create(EditionPaymentScheduleEntity entity, int userId)
        {
            try
            {
                var editionPaymentSchedule = new EditionPaymentSchedule
                {
                    EditionId              = entity.EditionId,
                    Name                   = entity.Name,
                    ActivationDate         = entity.ActivationDate,
                    ExpiryDate             = entity.ExpiryDate,
                    Installment1Percentage = entity.Installment1Percentage,
                    Installment1DueDate    = entity.Installment1DueDate,
                    Installment2Percentage = entity.Installment2Percentage,
                    Installment2DueDate    = entity.Installment2DueDate,
                    Installment3Percentage = entity.Installment3Percentage,
                    Installment3DueDate    = entity.Installment3DueDate,
                    Installment4Percentage = entity.Installment4Percentage,
                    Installment4DueDate    = entity.Installment4DueDate,
                    Installment5Percentage = entity.Installment5Percentage,
                    Installment5DueDate    = entity.Installment5DueDate,
                    CreatedOn              = DateTime.Now,
                    CreatedBy              = userId
                };

                _unitOfWork.EditionPaymentScheduleRepository.Insert(editionPaymentSchedule);
                _unitOfWork.Save();

                return(editionPaymentSchedule.EditionPaymentScheduleId);
            }
            catch (Exception exc)
            {
                return(-1);
            }
        }
        public ActionResult _AddEditionPaymentSchedule(EditionPaymentScheduleAddModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new { success = false, message = ModelState.GetErrors() }, JsonRequestBehavior.AllowGet));
            }

            var edition = EditionServices.GetEditionById(model.EditionId);

            if (edition == null)
            {
                return(Json(new { success = false, message = "Edition doesn't exist." }, JsonRequestBehavior.AllowGet));
            }

            var existingEditionPaymentSchedule = EditionPaymentScheduleServices.Get(model.EditionId, model.Name);

            if (existingEditionPaymentSchedule != null)
            {
                return(Json(
                           new
                {
                    success = false,
                    message =
                        $"Edition payment schedule already exists: {existingEditionPaymentSchedule.Name}"
                }, JsonRequestBehavior.AllowGet));
            }

            var editionPaymentSchedule = new EditionPaymentScheduleEntity
            {
                EditionId              = edition.EditionId,
                Name                   = model.Name,
                ActivationDate         = model.ActivationDate,
                ExpiryDate             = model.ExpiryDate,
                Installment1DueDate    = model.Installment1DueDate,
                Installment1Percentage = model.Installment1Percentage,
                Installment2DueDate    = model.Installment2DueDate,
                Installment2Percentage = model.Installment2Percentage,
                Installment3DueDate    = model.Installment3DueDate,
                Installment3Percentage = model.Installment3Percentage,
                Installment4DueDate    = model.Installment4DueDate,
                Installment4Percentage = model.Installment4Percentage,
                Installment5DueDate    = model.Installment5DueDate,
                Installment5Percentage = model.Installment5Percentage,
            };

            EditionPaymentScheduleServices.Create(editionPaymentSchedule, CurrentCedUser.CurrentUser.UserId);

            var scopeName = "Edition Payment Schedule";

            // UPDATE EDITION
            UpdateEditionUpdateInfo(edition);

            // DIFF
            var diff = new List <Variance>
            {
                new Variance
                {
                    Prop = scopeName, ValA = null,
                    ValB = editionPaymentSchedule.Name
                }
            };

            OnEditionUpdated(edition, diff);

            // UPDATE LOG
            var updatedFields = NotificationControllerHelper.GetUpdatedFieldsAsJson(scopeName,
                                                                                    new List <Variance> {
                new Variance {
                    Prop = scopeName
                }
            });

            UpdateLogInMemory(edition, updatedFields);

            return(Json(
                       new
            {
                success = true,
                message =
                    $"Edition payment schedule has been added: {editionPaymentSchedule.Name}"
            }, JsonRequestBehavior.AllowGet));
        }