private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                Contract result     = null;
                int      editResult = CRUDStatusCode.ERROR;

                _contractService     = new ContractService();
                _systemConfigService = new SystemConfigService();

                if (model == null)
                {
                    //Add
                    model = new Contract()
                    {
                        Code         = txtCode.Text,
                        CustomerCode = txtCustomerCode.Text,
                        //ContractTypeId = (int)cboContractType.SelectedValue,
                        StartDate = dtpStartDate.Value,
                        EndDate   = dtpEndDate.Value,
                        SumCost   = Utilities.GetDoubleFromTextBox(txtCost),
                        Discount  = Utilities.GetDoubleFromTextBox(txtDiscount),
                        Cost      = Utilities.GetDoubleFromTextBox(txtTotalCost)
                    };
                    result = _contractService.AddContract(model);
                    if (result != null)
                    {
                        model = result;
                        gbContractDetail.Visible = true;
                        _systemConfigService.UseLastContractNumber();
                        contractDetail = new ContractItem()
                        {
                            ContractCode = model.Code
                        };
                        txtCustomerCode.ReadOnly = true;
                        Utilities.ShowMessage(CommonMessage.ADD_SUCESSFULLY);
                        Logging.LogBusiness(string.Format("{0} {1} {2}",
                                                          Common.Session.GetUserName(),
                                                          Common.Constants.LogAction.Create, "hợp đồng mã " + model.Code),
                                            Common.Constants.BusinessLogType.Create);
                    }
                }
                else
                {
                    //Edit
                    model.CustomerCode = txtCustomerCode.Text;

                    //model.ContractTypeId = (int)cboContractType.SelectedValue;
                    model.StartDate = dtpStartDate.Value;
                    model.EndDate   = dtpEndDate.Value;
                    model.SumCost   = Utilities.GetDoubleFromTextBox(txtCost);
                    model.Cost      = Utilities.GetDoubleFromTextBox(txtTotalCost);
                    model.Discount  = Utilities.GetDoubleFromTextBox(txtDiscount);

                    editResult = _contractService.EditContract(model);
                    if (editResult == CRUDStatusCode.SUCCESS)
                    {
                        gbContractDetail.Visible = true;
                        Utilities.ShowMessage(CommonMessage.EDIT_SUCESSFULLY);
                        Logging.LogBusiness(string.Format("{0} {1} {2}",
                                                          Common.Session.GetUserName(),
                                                          Common.Constants.LogAction.Update, "hợp đồng mã " + model.Code),
                                            Common.Constants.BusinessLogType.Update);
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                _contractService     = null;
                _systemConfigService = null;
            }
        }
Ejemplo n.º 2
0
        public async Task <IHttpActionResult> AddContract(Guid contextId, string token1, string token2, string fileChecksum, string contextHash)
        {
            var response = await _service.AddContract(new ContractBindingModel(contextId, token1, token2, fileChecksum, contextHash));

            return(Ok(response));
        }