public async Task <IActionResult> CreateContract(CreateContractViewModel viewModel,
                                                         CancellationToken cancellationToken)
        {
            // Validate the model
            if (this.ValidateModel(viewModel))
            {
                try
                {
                    String accessToken = await this.HttpContext.GetTokenAsync("access_token");

                    CreateContractModel createContractModel = this.ViewModelFactory.ConvertFrom(viewModel);

                    // All good with model, call the client to create the golf club
                    CreateContractResponseModel createContractResponseModel =
                        await this.ApiClient.CreateContract(accessToken, this.User.Identity as ClaimsIdentity, createContractModel, cancellationToken);

                    // Merchant Created, redirect to the Merchant List screen
                    return(this.RedirectToAction("GetContractList", "Contract")
                           .WithSuccess("Contract Created Successful", $"Contract {viewModel.ContractDescription} successfully created"));
                }
                catch (Exception ex)
                {
                    // Something went wrong creating the contract
                    return(this.View("CreateContract").WithWarning("New Contract", Helpers.BuildUserErrorMessage("Error creating the contract")));
                }
            }

            // If we got this far, something failed, redisplay form
            return(this.View("CreateContract", viewModel));
        }
예제 #2
0
        public IActionResult Create()
        {
            var model = new CreateContractViewModel
            {
                SignedDate = DateTime.Now,
            };

            return(View(model));
        }
예제 #3
0
        private async Task CheckIfAlreadyExists(ModelStateDictionary modelState, CreateContractViewModel vm)
        {
            bool existingContract = await contractExistsAsync(vm.Contract.ContractName);

            // Check if ContractName exists, if yes, add model error...
            if (existingContract)
            {
                ModelState.AddModelError("Contract.ContractName", "Číslo rámcové smlouvy již existuje. Zvolte jiné, nebo upravte stávající.");
            }

            // return existingContract;
        }
예제 #4
0
        // GET: Contracts/Create
        public IActionResult Create()
        {
            CreateContractViewModel model = new CreateContractViewModel();
            List <UsersCheckList>   list  = new List <UsersCheckList>();

            model.Properties              = new SelectList(_context.Properties, "Id", "Name");
            model.Individuals             = _context.Individuals.Where(i => i.IsBlocked == false).ToList();
            model.IndividualEntrepreneurs = _context.IndividualEntrepreneurs.Where(e => e.IsBlocked == false).ToList();
            model.Companies = _context.Companies.Where(c => c.IsBlocked == false).ToList();
            model.Countries = new SelectList(Country.GetCountryList());

            return(View(model));
        }
예제 #5
0
        public async Task <IActionResult> Create(CreateContractViewModel model)
        {
            var cnt = await _mainRepository.QueryByNoAsync(model.No);

            if (cnt.Count > 0)
            {
                ModelState.AddModelError("No", "已存在合同编号:" + model.No);
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                await _mainRepository.CreateAsync(new Contract
                {
                    Id                       = Guid.NewGuid(),
                    No                       = model.No,
                    Name                     = model.Name,
                    Amount                   = model.Amount,
                    SignedDate               = model.SignedDate,
                    Deadline                 = model.Deadline,
                    PromisedDeadline         = model.PromisedDeadline,
                    JobContent               = model.JobContent,
                    ProjectLocation          = model.ProjectLocation,
                    Client                   = model.Client,
                    ClientContactPerson      = model.ClientContactPerson,
                    ClientContactPersonPhone = model.ClientContactPersonPhone,
                    AcceptWay                = (int)(model.AcceptWay),
                    SignStatus               = (int)(model.SignStatus),
                    AcceptStaffId            = model.AcceptStaffId,
                    ResponseStaffId          = model.ResponseStaffId
                });

                TempData["globalMessage"] = "创建成功";
            }
            catch (DbUpdateException /* ex */)
            {
                // Log the error(uncomment ex variable name and write a log.
                ModelState.AddModelError("", "无法保存更改。 " +
                                         "请重试, 如果该问题仍然存在 " +
                                         "请联系系统管理员。");
            }


            return(View());
        }
예제 #6
0
        public IActionResult VerifyContractNo([Bind(include: "No")] CreateContractViewModel model)
        {
            string message = null;
            var    result  = IsUnique(model.No);

            if (!result)
            {
                message = "已存在合同编号:" + model.No;
                return(Json(message));
            }
            else
            {
                return(Json(true));
            }
        }
        /// <summary>
        /// Converts from.
        /// </summary>
        /// <param name="createContractViewModel">The create contract view model.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">createContractViewModel</exception>
        public CreateContractModel ConvertFrom(CreateContractViewModel createContractViewModel)
        {
            if (createContractViewModel == null)
            {
                throw new ArgumentNullException(nameof(createContractViewModel));
            }

            CreateContractModel createContractModel = new CreateContractModel
            {
                OperatorId  = createContractViewModel.OperatorId,
                Description = createContractViewModel.ContractDescription
            };

            return(createContractModel);
        }
예제 #8
0
        public async Task <IActionResult> VerifyContractNo([Bind(include: "No")] CreateContractViewModel model)
        {
            string message = null;
            var    cnt     = await _mainRepository.QueryByNoAsync(model.No);

            if (cnt.Count > 0)
            {
                message = "已存在合同编号:" + model.No;
                return(Json(message));
            }
            else
            {
                return(Json(true));
            }
        }
예제 #9
0
        public async Task <IActionResult> Create()
        {
            Contract contract = new Contract();

            // Default values
            contract.SharedInfo.ReceiveDate = DateTime.Now;

            CreateContractViewModel vm = new CreateContractViewModel()
            {
                Contract = contract
            };

            await populateModelAsync(vm);
            await defaultEvePreselected(vm);

            return(View(vm));
        }
예제 #10
0
        public async Task <IActionResult> Create(CreateContractViewModel model)
        {
            //var cnt = await _mainRepository.QueryByNoAsync(model.No);
            //if (cnt.Count > 0)
            //{
            //    ModelState.AddModelError("No", "已存在合同编号:" + model.No);

            //}

            if (!IsUnique(model.No))
            {
                ModelState.AddModelError("No", "已存在合同编号:" + model.No);
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var contract = _mapper.Map <Contract>(model);

            try
            {
                await _contractRepository.CreateAsync(contract);

                StatusMessage = $"合同\"{contract.Name}\"成功创建";
            }
            catch (DbUpdateException ex)
            {
                // Log the error(uncomment ex variable name and write a log.
                ModelState.AddModelError("", "无法保存更改。 " +
                                         "请重试, 如果该问题仍然存在 " +
                                         "请联系系统管理员。");

                StatusMessage = $"合同/项目创建失败";
                throw;
                //return View(new CreateCMProjectViewModel());
            }

            return(RedirectToAction(nameof(ContractController.Index)));
        }
예제 #11
0
        public async Task <IActionResult> Create(CreateContractViewModel contractViewModel)
        {
            var contract = new Contract
            {
                CompanyId      = contractViewModel.CompanyId,
                StartDate      = contractViewModel.StartDate,
                IntervalMonths = contractViewModel.IntervalMonths,
                Price          = contractViewModel.Price,
                RenewalDate    = contractViewModel.StartDate.AddYears(contractViewModel.ContractLengthYears)
            };

            if (ModelState.IsValid)
            {
                contract.Id = Guid.NewGuid();
                _context.Add(contract);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Details", "Companies", new { id = contractViewModel.CompanyId }));
            }
            ViewData["CompanyId"] = contractViewModel.CompanyId;
            return(View(contractViewModel));
        }
예제 #12
0
        public async Task <IActionResult> Create(CreateContractViewModel vm)
        {
            // Check for duplicate, raise Invalid ModelState if the same ContractName is found
            await CheckIfAlreadyExists(ModelState, vm);

            if (!ModelState.IsValid)
            {
                TempData["error"] = "Nepovedlo se vytvořit...";
                await populateModelAsync(vm);
                await defaultEvePreselected(vm);

                return(View(vm));
            }

            // If user inputs Price, write ExchangeRate and compute PriceCzk
            if (vm.Contract.SharedInfo.Price != null)
            {
                string currencyName = await _db.Currency
                                      .Where(x => x.CurrencyId == vm.Contract.SharedInfo.CurrencyId).Select(x => x.Name).FirstOrDefaultAsync();

                string exchangeRateStr = getCurrencyStr(currencyName.Replace(",", "."));
                vm.Contract.SharedInfo.ExchangeRate = Decimal.Parse(exchangeRateStr, CultureInfo.InvariantCulture);
                vm.Contract.SharedInfo.PriceCzk     = (int?)(vm.Contract.SharedInfo.Price * vm.Contract.SharedInfo.ExchangeRate);
            }

            vm.Contract.CreatedBy    = User.GetLoggedInUserName();
            vm.Contract.ModifiedBy   = vm.Contract.CreatedBy;
            vm.Contract.CreatedDate  = DateTime.Now;
            vm.Contract.ModifiedDate = vm.Contract.CreatedDate;

            await _db.AddAsync(vm.Contract);

            await _db.SaveChangesAsync(User.GetLoggedInUserName());

            TempData["success"] = "Rámcová smlouva vytvořena";
            return(RedirectToAction("Index"));
        }
예제 #13
0
 public async Task<IActionResult> Create(CreateContractViewModel createContractViewModel)
 {
     return View();
 }
예제 #14
0
        public async Task <IActionResult> Create(CreateContractViewModel model)
        {
            Contract contract = new Contract()
            {
                ContractNumber  = model.ContractNumber,
                ContractTime    = model.ContractTime,
                DateOfOffer     = model.DateOfOffer,
                Country         = model.Country,
                Autorolongation = model.CheckAutorolongation
            };

            _context.Contracts.Add(contract);
            await _context.SaveChangesAsync();

            UploadFiles(contract, model.contractFiles);

            if (model.actNumbers != null)
            {
                foreach (var actNumber in model.actNumbers)
                {
                    if (actNumber != "$$")
                    {
                        Act act = new Act()
                        {
                            ActNumber = actNumber, ContractId = contract.Id
                        };
                        _context.Acts.Add(act);
                        _context.SaveChanges();
                        UploadFiles(act, model.actFiles);
                    }
                }
            }
            if (model.supplementaryNumbers != null)
            {
                foreach (var suppNumber in model.supplementaryNumbers)
                {
                    if (suppNumber != "$$")
                    {
                        Supplementary supp = new Supplementary()
                        {
                            SupplementaryNumber = suppNumber, ContractId = contract.Id
                        };
                        _context.Supplementaries.Add(supp);
                        _context.SaveChanges();
                        UploadFiles(supp, model.suppFiles);
                    }
                }
            }


            int contractId = contract.Id;

            if (model.propertyId != null && model.valueProperty != null && model.valueProperty.Any() && model.propertyId.Any())
            {
                for (int i = 0; i < model.valueProperty.Count; i++)
                {
                    Property test         = _context.Properties.FirstOrDefault(u => u.Id == model.propertyId[i]);
                    Contract contractTest = _context.Contracts.FirstOrDefault(u => u.ContractNumber == contract.ContractNumber);
                    _context.ContractPropertieses.Add(new ContractProperties()
                    {
                        Value      = model.valueProperty[i],
                        PropertyId = test.Id,
                        ContractId = contractTest.Id
                    });
                    _context.SaveChanges();
                }
            }
            if (model.CounterpartiesId != null)
            {
                for (int i = 0; i < model.CounterpartiesId.Count; i++)
                {
                    _context.ContractCounterparties.Add(new ContractCounterparty()
                    {
                        ContractId     = _context.Contracts.FirstOrDefault(c => c.Id == contract.Id).Id,
                        CounterpartyId = model.CounterpartiesId[i]
                    });
                    await _context.SaveChangesAsync();
                }
            }
            return(RedirectToAction(nameof(Index)));
        }
예제 #15
0
 public CreateContractView()
 {
     InitializeComponent();
     DataContext = new CreateContractViewModel();
 }
예제 #16
0
        // GET: ContractBuy/Create
        public ActionResult Create()
        {
            // For users
            IEnumerable <long> users = null;

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://localhost:8081/");
                //HTTP GET
                var responseTask = client.GetAsync("/Contract_Buy/getIdUser");
                responseTask.Wait();

                var result = responseTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    var readTask = result.Content.ReadAsAsync <IEnumerable <long> >();
                    readTask.Wait();

                    users = readTask.Result;
                }
                else //web api sent error response
                {
                    //log response status here..

                    users = Enumerable.Empty <long>();

                    ModelState.AddModelError(string.Empty, "Server error. Please contact administrator.");
                }
            }

            // FOR properties

            IEnumerable <int> properties = null;

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://localhost:8081/");
                //HTTP GET
                var responseTask = client.GetAsync("/Contract_Buy/getIdPropertyBuy");
                responseTask.Wait();

                var result = responseTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    var readTask = result.Content.ReadAsAsync <IEnumerable <int> >();
                    readTask.Wait();

                    properties = readTask.Result;
                }
                else //web api sent error response
                {
                    //log response status here..

                    properties = Enumerable.Empty <int>();

                    ModelState.AddModelError(string.Empty, "Server error. Please contact administrator.");
                }
            }
            var model = new CreateContractViewModel
            {
                Users      = users,
                Properties = properties
            };


            return(View(model));
        }
 /// <summary>
 /// Validates the model.
 /// </summary>
 /// <param name="viewModel">The view model.</param>
 /// <returns></returns>
 private Boolean ValidateModel(CreateContractViewModel viewModel)
 {
     return(this.ModelState.IsValid);
 }
        public async Task <IActionResult> CreateContract(CancellationToken cancellationToken)
        {
            CreateContractViewModel viewModel = new CreateContractViewModel();

            return(this.View("CreateContract", viewModel));
        }