public Task <DataResult <DTOQuotation> > GetQuotationByIdAsync(string quotationId) { return(Task.Run(() => { var quotationDTO = new DTOQuotation(); Expression <Func <Quotation, object> >[] includes = { x => x.Status, x => x.CustomerExchange.Car, x => x.CustomerExchange.Customer, x => x.CustomerExchange.Customer.Branch, x => x.CustomerExchange.Customer.CustomerType }; var quotation = quotationRepository.GetFirstOrDefault(x => x.Id == quotationId, includes: includes); if (quotation != null) { quotationDTO = _mapper.Map <DTOQuotation>(quotation); } return new DataResult <DTOQuotation> { Errors = new List <ErrorDescriber>(), Target = quotationDTO }; })); }
public Task <DataResult <DTOQuotation> > CreateQuotationAsync(DTOQuotation quotationDTO) { return(Task.Run(() => { var createdQuotationDTO = new DTOQuotation(); if (!quotationRepository.ExistByCondition(x => x.Id == quotationDTO.Id)) { var quotation = _mapper.Map <Quotation>(quotationDTO); var lastQuotation = quotationRepository.Identity(x => x.GenerateId); var identityNumber = lastQuotation != null ? lastQuotation.GenerateId : 0; quotation.Id = GetShortNameByBranchId(quotationDTO.BranchId) + IdentityGenerate.Create(identityNumber, new string[] { "", EntityPrefix.Quotation.ToDefaultValue() }, NumberUnitType.Large); quotation.StartDate = DateTime.Now; quotation.EntryDate = DateTime.Now; quotation.StatusId = (int)DTOQuotationStatusName.RequestFromCustomer; quotation.Branch = branchRepository.GetById(quotation.BranchId); quotation.Status = quotationStatusRepository.GetById(quotation.StatusId); var result = quotationRepository.Insert(quotation); _unitOfWork.SaveChanges(); createdQuotationDTO = _mapper.Map <DTOQuotation>(quotation); } return new DataResult <DTOQuotation> { Errors = new List <ErrorDescriber>(), Target = createdQuotationDTO }; })); }
private async Task <IHttpActionResult> SaveQuotationAndItems(DTOQuotation quotationDTO, List <DTOQuotationItem> quotationItemsDTO, string branchId, int customerExchangeId) { quotationDTO.BranchId = branchId; quotationDTO.CustomerExchangeId = customerExchangeId; var quotationResult = await _serviceParameter.QuotationService.CreateQuotationAsync(quotationDTO); if (quotationResult.HasErrors) { var errorResult = ErrorResult(quotationResult.Errors); return(Ok(errorResult)); } var quotationItemResult = await _serviceParameter.QuotationService.CreateQuotationItemsAsync(quotationResult.Target.Id, quotationItemsDTO); if (quotationItemResult.HasErrors) { var errorResult = ErrorResult(quotationItemResult.Errors); return(Ok(errorResult)); } var successResult = SuccessResult(true); return(Ok(successResult)); }
public Task <DataResult <bool> > EditQuotationAsync(DTOQuotation quotationDTO) { return(Task.Run(() => { var quotation = _mapper.Map <Quotation>(quotationDTO); quotation.UpdateDate = DateTime.Now; if (quotation.StatusId != (int)DTOQuotationStatusName.CheckUp) { quotation.NextKm = null; quotation.NextMaintenanceDate = null; } else { quotation.CompleteDate = DateTime.Now; } quotationRepository.Update(quotation); _unitOfWork.SaveChanges(); return new DataResult <bool> { Errors = new List <ErrorDescriber>(), Target = true }; })); }
public async Task <IHttpActionResult> Put(string quotationId, [FromBody] DTOQuotation quotationDTO) { return(await ExecuteServiceReturnDefaultResult(() => _serviceParameter.QuotationService.EditQuotationAsync(quotationDTO), false)); }