Example #1
0
        public async Task <ContractDto> Handle(ContractAddCommand request, CancellationToken cancellationToken)
        {
            var contract = Contract.CreateContract(
                request.EmployedAt,
                request.EmployedEndAt,
                request.BaseSalary,
                request.IdJobPosition,
                request.IdWorker,
                request.IdentifierZusNumber,
                request.IsSick,
                request.IsAnnuitant,
                request.IsPensioner,
                request.IsHealthy,
                request.IsLf,
                request.IsGebf,
                request.IsLeave,
                request.IsSickLeave,
                request.IsPkzp,
                request.WorkingTime,
                request.EntireInternship,
                request.ProfessionInternship,
                request.ServiceInternship,
                request.JubileeInternship
                );
            await _contractRepository.AddAsync(contract);

            return(new ContractDto {
                Id = contract.Id
            });
        }
        public async Task <Contract> AddAsync(Contract entity)
        {
            var createdEntity = await _ContractRepository.AddAsync(entity);

            //  await _BaseRepository.Sav();
            return(createdEntity);
        }
        public async Task <Response <int> > Handle(CreateNewContractCommand request, CancellationToken cancellationToken)
        {
            var currentUser = await _authenticatedUserService.GetCurentApplicationUser();

            var contract = new Domain.Entities.Contract
            {
                CompanyId          = currentUser.CompanyId.Value,
                ContractTypeId     = request.ContractTypeId,
                ExpiredDate        = request.ContractExpiredDate,
                Status             = ContractStatus.Draft,
                TotalValue         = request.ContractValue,
                CreatedBy          = currentUser.UserName,
                Created            = DateTime.Now,
                ContractPlace      = request.ContractPlace,
                Content            = request.ContractContent,
                Name               = request.ContractName,
                ContractNum        = request.ContractNum,
                Title              = request.ContractTitle,
                CustomerId         = request.CustomerId,
                Header             = request.Header,
                AInformation       = request.AInformation,
                BInformation       = request.BInformation,
                ContractValue      = request.Value,
                ContractLaw        = request.ContractLaw,
                Footer             = request.Footer,
                BelongToContractId = request.BelongToContractId
            };

            await _contractRepository.AddAsync(contract);

            return(new Response <int>(contract.Id));
        }
Example #4
0
        /// <summary>
        /// The asynchronous method for registering a new customer's contract.
        /// </summary>
        /// <param name="customer">The customer data for the new contract.</param>
        /// <param name="riskQuestions">The customer's risk question's asnwers.</param>
        /// <returns>A <see cref="Customer"/> object for the registered new contract.</returns>
        public async Task <Contract> CreateAsync(Customer customer, List <RiskQuestion> riskQuestions)
        {
            //Instantiating the new contract.
            Contract contract = new Contract();

            //Checking the received risk questions' answers - retrieving the registered active questions for comparison.
            List <RiskQuestion> riskQuestionsDB = _riskQuestionService.List(1);

            //Checking if there's as many received answers as there are active questions.
            if (riskQuestions.Count().Equals(riskQuestionsDB.Count()))
            {
                //Setting the ID of the questions.
                for (int i = 0; i < riskQuestionsDB.Count(); i++)
                {
                    riskQuestions[i].ID       = riskQuestionsDB[i].ID;
                    riskQuestions[i].Question = riskQuestionsDB[i].Question;
                    riskQuestions[i].StatusID = riskQuestionsDB[i].StatusID;
                    riskQuestions[i].Created  = riskQuestionsDB[i].Created;
                }

                //Creating the list of customer-risk questions object.
                List <CustomerRiskQuestion> customerRiskQuestions = riskQuestions.Select(x => new CustomerRiskQuestion
                {
                    RiskQuestionAnswer = x.Answer,
                    RiskQuestionID     = x.ID,
                    Customer           = customer,
                    Contract           = contract,
                    Created            = DateTime.Now
                }).OrderBy(x => x.ID).ToList();

                //Setting the contract's total risk points.
                SetContractRiskPoints(customer, customerRiskQuestions, ref contract);

                //Setting the auto insurance.
                SetAutoInsurance(customer, ref contract);

                //Setting the disability insurance.
                SetDesabilityInsurance(customer, ref contract);

                //Setting the home insurance.
                SetHomeInsurance(customer, ref contract);

                //Setting the life insurance.
                SetLifeInsurance(customer, ref contract);

                //Setting the contract's and the customer's remaining information.
                contract.CustomerRiskQuestions = customerRiskQuestions;
                contract.Created = customer.Created = DateTime.Now;

                //Registering into database.
                contract = await _contractRepository.AddAsync(contract, true);
            }
            else
            {
                throw new Exception("The submitted answers do not correspond to the active questions registered in database.");
            }

            return(contract);
        }
        public async Task <ActionResult> Create(ContractViewModel contract)
        {
            var tenants      = (await _tenantRepository.GetAllAsync()).OrderBy(t => t.Name);
            var rooms        = (await _roomRepository.GetAllAsync()).OrderBy(r => r.Address);
            var accrualTypes = (await _accrualTypeRepository.GetAllAsync()).OrderBy(t => t.Name);

            var tenantsSelectList      = new SelectList(tenants, "Id", "Name", tenants.First(t => t.Id == contract.TenantId));
            var roomsSelectList        = new SelectList(rooms, "Id", "Address", rooms.First(r => r.Id == contract.RoomId));
            var accrualTypesSelectList = new SelectList(accrualTypes, "Id", "Name", accrualTypes.First(t => t.Id == contract.AccrualTypeId));

            contract.Id           = System.Guid.NewGuid().ToString();
            contract.Tenants      = tenantsSelectList;
            contract.Rooms        = roomsSelectList;
            contract.AccrualTypes = accrualTypesSelectList;
            var accrual = ContractViewModel.FromContractViewModel(contract);
            var room    = await _roomRepository.GetByIdAsync(contract.RoomId);

            if (!ModelState.IsValid)
            {
                return(View(contract));
            }

            if (contract.AccrualTypeId == "d739e49d-6219-46e1-968d-498e80a5681c" && room.IsOccupied)
            {
                ModelState.AddModelError(string.Empty, "Выбранное помещение уже арендуется.");
                return(View(contract));
            }
            if (contract.AccrualTypeId != "d739e49d-6219-46e1-968d-498e80a5681c" && !room.IsOccupied)
            {
                ModelState.AddModelError(string.Empty, @"Для составления договора на
                    сопроводительные услуги необходимо выбрать помещение, на которое составлен договор аренды.");
                return(View(contract));
            }

            try
            {
                await _contractRepository.AddAsync(accrual);

                await _roomRepository.UpdateAsync(room);

                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception e)
            {
                ModelState.AddModelError("", e.Message);

                return(View(contract));
            }
        }
        //public async Task<IEnumerable<Contract>> FindByPerformerIdAndEmployerId(int performerId, int employerId)
        //{
        //    return await _contractRepository.FindByPerformerIdAndEmployerId(performerId, employerId);
        //}

        public async Task <ContractResponse> SaveAsync(Contract contract)
        {
            try
            {
                await _contractRepository.AddAsync(contract);

                await _unitOfWork.CompleteAsync();

                return(new ContractResponse(contract));
            }
            catch (Exception ex)
            {
                return(new ContractResponse($"An error ocurred while saving the contract: {ex.Message}"));
            }
        }
Example #7
0
        public async Task <ActionResult <ContractForGetDTO> > Post(ContractForAddDTO model)
        {
            if (await _contractRepository.IsExist(model.Name).ConfigureAwait(true))
            {
                return(Conflict(new ApiResponse(409, StringConsts.EXISTED)));
            }

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

            await _contractRepository.AddAsync(contract).ConfigureAwait(true);

            await _unitOfWork.CompleteAsync().ConfigureAwait(true);

            ContractForGetDTO contractDto = _mapper.Map <ContractForGetDTO>(contract);

            return(Ok(contractDto));
        }