コード例 #1
0
        public bool Edit(ContractEditModel model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Contracts
                    .Single(e => e.ContractId == model.ContractId);         // && e.OwnerId == _userId

                entity.DevId  = model.DevId;
                entity.TeamId = model.TeamId;
                return(ctx.SaveChanges() == 1);
            }
        }
コード例 #2
0
        public IHttpActionResult Put(ContractEditModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = LocalContractService();

            if (!service.Edit(model))
            {
                return(InternalServerError());
            }

            return(Ok(model));
        }
コード例 #3
0
        public ContentResult SaveContract(ContractEditModel model)
        {
            if ((model.ID == 0) && !model.IsDeleted)
            {
                // новое
                var contract = new Contract();
                // исправить даты
                if (model.Date.HasValue && model.Date.Value.Kind != DateTimeKind.Utc)
                {
                    model.Date = model.Date.Value.ToUniversalTime();
                }

                if (model.BeginDate.HasValue && model.BeginDate.Value.Kind != DateTimeKind.Utc)
                {
                    model.BeginDate = model.BeginDate.Value.ToUniversalTime();
                }

                if (model.EndDate.HasValue && model.EndDate.Value.Kind != DateTimeKind.Utc)
                {
                    model.EndDate = model.EndDate.Value.ToUniversalTime();
                }

                contract.LegalId               = model.LegalId;
                contract.CurrencyRateUseId     = model.CurrencyRateUseId;
                contract.Number                = model.Number;
                contract.OurLegalId            = model.OurLegalId;
                contract.BankAccountId         = model.BankAccountId;
                contract.ContractRoleId        = model.ContractRoleId;
                contract.ContractTypeId        = model.ContractTypeId;
                contract.PaymentTermsId        = model.PaymentTermsId;
                contract.OurBankAccountId      = model.OurBankAccountId;
                contract.OurContractRoleId     = model.OurContractRoleId;
                contract.ContractServiceTypeId = model.ContractServiceTypeId;
                contract.Comment               = model.Comment;
                contract.IsFixed               = model.IsFixed;
                contract.IsProlongation        = model.IsProlongation;
                contract.Date            = model.Date;
                contract.BeginDate       = model.BeginDate;
                contract.EndDate         = model.EndDate;
                contract.PayMethodId     = model.PayMethodId;
                contract.AgentPercentage = model.AgentPercentage;

                var id = contractLogic.CreateContract(contract);
                SaveContractCurrencies(id, model.Currencies);

                return(Content(JsonConvert.SerializeObject(new { ID = id })));
            }
            else
            {
                var contract = contractLogic.GetContract(model.ID);

                // проверка прав участника
                if (!participantLogic.IsAllowedActionByContractor(10, legalLogic.GetLegal(contract.LegalId).ContractorId.Value, CurrentUserId))
                {
                    return(Content(JsonConvert.SerializeObject(new { ActionId = 10, Message = "У вас недостаточно прав на выполнение этого действия." })));
                }

                if (model.IsDeleted)
                {
                    // удалить договор
                    contractLogic.DeleteContract(model.ID);
                }
                else
                {
                    #region marks

                    var mark = contractLogic.GetContractMarkByContract(model.ID);
                    if ((mark != null) && (mark.IsContractChecked))
                    {
                        return(Content(JsonConvert.SerializeObject(new { ActionId = 10, Message = "Договор проверен, редактирование невозможно." })));
                    }

                    #endregion

                    // исправить даты
                    if (model.Date.HasValue && model.Date.Value.Kind != DateTimeKind.Utc)
                    {
                        model.Date = model.Date.Value.ToUniversalTime();
                    }

                    if (model.BeginDate.HasValue && model.BeginDate.Value.Kind != DateTimeKind.Utc)
                    {
                        model.BeginDate = model.BeginDate.Value.ToUniversalTime();
                    }

                    if (model.EndDate.HasValue && model.EndDate.Value.Kind != DateTimeKind.Utc)
                    {
                        model.EndDate = model.EndDate.Value.ToUniversalTime();
                    }

                    contract.LegalId               = model.LegalId;
                    contract.CurrencyRateUseId     = model.CurrencyRateUseId;
                    contract.Number                = model.Number;
                    contract.OurLegalId            = model.OurLegalId;
                    contract.ContractRoleId        = model.ContractRoleId;
                    contract.ContractTypeId        = model.ContractTypeId;
                    contract.PaymentTermsId        = model.PaymentTermsId;
                    contract.OurContractRoleId     = model.OurContractRoleId;
                    contract.ContractServiceTypeId = model.ContractServiceTypeId;
                    contract.Comment               = model.Comment;
                    contract.IsFixed               = model.IsFixed;
                    contract.IsProlongation        = model.IsProlongation;
                    contract.Date            = model.Date;
                    contract.BeginDate       = model.BeginDate;
                    contract.EndDate         = model.EndDate;
                    contract.PayMethodId     = model.PayMethodId;
                    contract.AgentPercentage = model.AgentPercentage;

                    contractLogic.UpdateContract(contract);

                    SaveContractCurrencies(contract.ID, model.Currencies);
                }
            }

            return(Content(JsonConvert.SerializeObject("")));
        }