Exemple #1
0
        public async Task <IActionResult> Rent(int cid, int adid)
        {
            var tenantid = _userService.GetUserId();
            await _contractRepository.AddContract(adid, cid, tenantid);

            return(RedirectToAction(nameof(Index)));
        }
        private bool KeepContract(Domain.Car car, Domain.Client client)
        {
            Domain.Contract contract = Domain.Contract.CreateContract(car, client);
            contract.CarId    = car.Id;
            contract.ClientId = client.Id;
            Console.WriteLine("Please enter the contract type is Debit or Credit ?");
            string type = Console.ReadLine();

            try
            {
                if (type.ToLower() == ContractType.Debit.ToString().ToLower())
                {
                    contract.TotalCost    = car.Price;
                    contract.Type         = ContractType.Debit;
                    contract.FirstPayment = contract.TotalCost;
                }
                else
                {
                    Console.WriteLine("How much months will contract keep?");
                    short months = short.Parse(Console.ReadLine());
                    contract.Months        = months;
                    contract.FirstPayment  = car.Price / contract.Months.Value;
                    contract.Type          = ContractType.Credit;
                    contract.MonthsPayment = contract.FirstPayment;
                    contract.TotalCost     = car.Price;
                }
                _contractRepository.AddContract(contract);
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Exemple #3
0
        public ViewResult AddContract(contract contract)
        {
            ViewBag.message = "添加信息成功!";

            var result = repository.AddContract(contract);

            if (result == false)
            {
                ViewBag.message = "添加信息失败!";
            }

            return(View(new AddContractViewModel()));
        }
Exemple #4
0
        public async Task <ActionResult <Contract> > AddContract(ContractCreate contractCreate)
        {
            var contract = _mapper.Map <Contract>(contractCreate);

            _contractRepository.AddContract(contract);

            if (await _contractRepository.SaveAllAsync())
            {
                return(Ok(contract));
            }

            return(BadRequest("Failed to create Customer"));
        }
        public async Task <IActionResult> AddContract([FromBody] JObject item)
        {
            try
            {
                return(Ok(await _repo.AddContract(item["contract"].ToObject <Contract>(), item["contractDetail"].ToObject <ContractDetail>())));
            }

            catch (Exception ex)
            {
                _logger.Write(LogEventLevel.Error, ex, "AddContract failed: {ex.message}");
                var returnResult = ex.InnerException?.InnerException?.Message ?? ex.Message;
                return(BadRequest(returnResult));
            }
        }
        public IActionResult SellCar([FromBody] ContractViewModel contract)
        {
            var car = _carRepository.FindCar(contract.CarNumber);

            if (car is null)
            {
                return(StatusCode(404, "The car was not found"));
            }

            var client = _clientRepository.FindClient(contract.ClientPassportId);

            if (client is null)
            {
                client = new Client
                {
                    Name      = contract.ClientName,
                    PasportId = contract.ClientPassportId
                };
                _clientRepository.AddClient(client);
            }
            try
            {
                _carRepository.SellCar(car, new Client
                {
                    Name      = contract.ClientName,
                    PasportId = contract.ClientPassportId
                });
                _contractRepository.AddContract(new Contract
                {
                    Car           = car,
                    Client        = client,
                    Type          = contract.Type,
                    TotalCost     = contract.TotalCost,
                    FirstPayment  = contract.FirstPayment,
                    Months        = contract.Months,
                    MonthsPayment = contract.MonthsPayment,
                    CarId         = car.Id,
                    ClientId      = client.Id
                });
                return(Ok("Car suucessfully sold"));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, "There is something wrong in the system. Please try again later :("));
            }
        }
Exemple #7
0
        public ActionResult Post([FromBody] ContractDto contractModel)
        {
            _logger.LogInformation($"[ContractController] - Post method started at {DateTime.Now}.");

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

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

            _contractRepository.AddContract(contract);

            var key = contract.ContractNr.Replace(" ", "-").ToLower();

            return(Created("api/contract/" + key, null));
        }
 public void AddContract(Contracts contract)
 {
     _contractRepository.AddContract(contract);
 }