private void SetCustomerInfoToCar(CollectionSheetRequestDTO sheet) { if (!sheet.CollectionCar.CollectionCarDetails.Any()) { return; } foreach (var car in sheet.CollectionCar.CollectionCarDetails) { FormatDataCar(car.Car, sheet); car.Status = Status.Active; car.CreatedBy = sheet.CollectionCar.CreatedBy; if (car.CreatedDate.Year == 1) { car.CreatedDate = DateTime.Now.Date; } if (car.IsInsurance) { if (car.InsuranceExpiredDate.HasValue) { car.InsuranceExpiredDate = new DateTime(car.InsuranceExpiredDate.Value.Year, car.InsuranceExpiredDate.Value.Month, car.InsuranceExpiredDate.Value.Day); } } else { if (car.IntendInsuranceDate.HasValue) { car.IntendInsuranceDate = new DateTime(car.IntendInsuranceDate.Value.Year, car.IntendInsuranceDate.Value.Month, car.IntendInsuranceDate.Value.Day); } } } }
private void ValidateRequest_Create(CollectionSheetRequestDTO input) { if (input == null) { throw new UserException(ErrorStatusReturn.REQUEST_NULL); } }
private void IsExistedTransaction(CollectionSheetRequestDTO sheet) { //var transactionFound =_inforCustomerRepository.FirstOrDefault(n => n.TransactionCode == input.TransactionCode); //if (transactionFound != null) // throw new UserException(ErrorStatusReturn.TRANSACTION_CODE_ALREADY_EXIST); }
private void InactiveOldCollectionCar(CollectionSheetRequestDTO sheet) { CollectionCar collectionCar = _collectionCarRepository.FirstOrDefault(x => x.Id == sheet.CollectionCar.Id); collectionCar.Status = Status.InActive; _collectionCarRepository.Update(collectionCar); }
private void CreateCommonCollectionSheet(CollectionSheetRequestDTO sheet) { SetCustomerInfoToCar(sheet); FormatDataCustomerBeforeInsert(sheet); sheet.CollectionCar.CollectionSheet = Mapper.Map <CollectionSheetDTO>(sheet); FormatDataCollectionCarAndSheet(sheet); }
private void InactiveOldCar(CollectionSheetRequestDTO sheet) { List <string> plates = sheet.CollectionCar.CollectionCarDetails.Select(x => x.Car.Plate).ToList(); List <Car> listCar = _carRepository.FindAll().Where(x => plates.Contains(x.Plate)).ToList(); listCar.ForEach(x => { x.Status = Status.InActive; _carRepository.Update(x); sheet.IsUpdateOldCar = true; }); sheet.CollectionCar.CollectionCarDetails.Select(x => x.Car).Select(x => x.Id).ToList().ForEach(x => { if (!listCar.Select(y => y.Id).Contains(x)) { Car car = _carRepository.FirstOrDefault(y => y.Id == x); if (car != null) { car.Status = Status.InActive; _carRepository.Update(car); sheet.IsUpdateOldCar = true; } } }); }
private InfoCustomer FindInfoCustomerExsitedInDB(CollectionSheetRequestDTO sheet) { InfoCustomer inforCustomer = _infoCustomerRepository.FindAll(x => x.Status == Status.Active) .FirstOrDefault(x => x.IdentityNumber == sheet.InfoCustomer.IdentityNumber && x.CustomerPhone == sheet.InfoCustomer.CustomerPhone); return(inforCustomer); }
private void FormatDataCar(CarDTO car, CollectionSheetRequestDTO sheet) { car.CollectorPhoneNumber = sheet.InfoCustomer.CustomerPhone; car.CollectorIndentityNumber = sheet.InfoCustomer.IdentityNumber; car.Status = Status.Active; car.CreatedBy = sheet.CollectionCar.CreatedBy; car.Plate = car.Plate.ToUpper().Trim(); car.TransactionCode = sheet.TransactionCode; }
private void SetStatusAndMasterDataForCollectionSheet(CollectionSheetRequestDTO sheet) { if (sheet.IsUpdateOldCar || sheet.IsUpdateoldInfoCustomer || sheet.InfoCustomer.IsGetDataFromPTI || sheet.InfoCustomer.IsGetDataFromIC) { sheet.BriefType = BriefType.RE_NEW_BRIEF; } else { sheet.BriefType = BriefType.NEW_BRIEF; } sheet.BriefStatus = BriefStatus.SUCCESS; }
private void FormatDataCustomerBeforeInsert(CollectionSheetRequestDTO sheet) { sheet.InfoCustomer.IdentityNumber = string.IsNullOrEmpty(sheet.InfoCustomer.IdentityNumber) ? string.Empty : sheet.InfoCustomer.IdentityNumber.Trim(); sheet.InfoCustomer.CustomerName = string.IsNullOrEmpty(sheet.InfoCustomer.CustomerName) ? string.Empty : sheet.InfoCustomer.CustomerName.Trim().ToUpper(); sheet.InfoCustomer.CustomerPhone = string.IsNullOrEmpty(sheet.InfoCustomer.CustomerPhone) ? string.Empty : sheet.InfoCustomer.CustomerPhone.Trim().ToUpper(); sheet.InfoCustomer.Status = Status.Active; sheet.InfoCustomer.IsDeleted = false; sheet.InfoCustomer.TransactionCode = sheet.TransactionCode; }
private void InactiveOldCollectionCarDetail(CollectionSheetRequestDTO sheet) { List <string> plates = sheet.CollectionCar.CollectionCarDetails.Select(x => x.Car.Plate).ToList(); List <CollectionCarDetail> listCollectionCarDetail = _collectionCarDetailRepository .FindAll().Where(x => sheet.CollectionCar.CollectionCarDetails.Select(y => y.Id).Contains(x.Id)).ToList(); listCollectionCarDetail.ForEach(x => { x.Status = Status.InActive; _collectionCarDetailRepository.Update(x); }); }
public ApiJsonResult CreateNewInforCustomerAndCar([FromBody] CollectionSheetRequestDTO sheet) { try { ValidateRequest_Create(sheet); return(new ApiJsonResult(true, _inforCustomerService.Create(sheet))); } catch (Exception ex) { return(ProcessException(ex)); } }
public ApiJsonResult Update([FromBody] CollectionSheetRequestDTO sheet) { try { ValidateRequestUpdate(sheet); _collectionSheetService.Update(sheet); return(new ApiJsonResult(true, null)); } catch (Exception ex) { return(ProcessException(ex)); } }
public void Update(CollectionSheetRequestDTO sheet) { CheckDateAllowedUpdate(sheet); InactiveOldCollectionSheet(sheet); InactiveOldInfoCustomer(sheet); InactiveOldCollectionCar(sheet); InactiveOldCar(sheet); InactiveOldCollectionCarDetail(sheet); FormatDataBeforeUpdating(sheet); CreateCommonCollectionSheet(sheet); InsertCollectionCar(sheet.CollectionCar); _unitOfWork.Commit(); }
private void SetUpdateCustomerInfoToCarInfor(CollectionSheetRequestDTO sheet) { if (sheet.CollectionCar.CollectionCarDetails.Any()) { foreach (var car in sheet.CollectionCar.CollectionCarDetails) { car.Car.CollectorPhoneNumber = sheet.InfoCustomer.CustomerPhone; car.Car.CollectorIndentityNumber = sheet.InfoCustomer.IdentityNumber; car.Car.Status = Status.Active; car.Car.UpdatedBy = sheet.UserCreateId; } } }
private void InactiveOldCarWhenCreate(CollectionSheetRequestDTO sheet) { List <string> plates = sheet.CollectionCar.CollectionCarDetails.Select(x => x.Car.Plate).ToList(); List <Car> listCar = _carRepository.FindAll().Where(x => plates.Contains(x.Plate)).ToList(); sheet.IsUpdateOldCar = false; listCar.ForEach(x => { x.Status = Status.InActive; _carRepository.Update(x); sheet.IsUpdateOldCar = true; }); }
private void SetCustomerInfoToCarAndUnactiveOldCar(CollectionSheetRequestDTO sheet) { if (!sheet.CollectionCar.CollectionCarDetails.Any()) { return; } InactiveOldCar(sheet); foreach (var car in sheet.CollectionCar.CollectionCarDetails) { FormatDataCar(car.Car, sheet); } }
private void InactiveOldInfoCustomerWhenCreate(CollectionSheetRequestDTO sheet) { List <InfoCustomer> listInforCustomer = _infoCustomerRepository.FindAll() .Where(x => sheet.InfoCustomer.CustomerPhone == x.CustomerPhone && sheet.InfoCustomer.IdentityNumber == x.IdentityNumber).ToList(); sheet.IsUpdateoldInfoCustomer = false; listInforCustomer.ForEach(x => { x.Status = Status.InActive; _infoCustomerRepository.Update(x); sheet.IsUpdateoldInfoCustomer = true; }); }
private void ValidateRequestUpdate(CollectionSheetRequestDTO sheet) { if (sheet.InfoCustomer == null) { throw new UserException(ErrorStatusReturn.INFO_CUSTOMER_NOT_VALID); } if (sheet.CollectionCar.CollectionCarDetails == null) { throw new UserException(ErrorStatusReturn.LIST_CAR_DETAIL_NULL); } if (sheet.TransactionCode == null) { throw new UserException(ErrorStatusReturn.TRANSACTION_CODE_NULL); } }
private void CheckDateAllowedUpdate(CollectionSheetRequestDTO sheet) { int day = DateTime.Now.Day; int month = DateTime.Now.Month; DateTime lastOfThisMonth = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month)); CollectionSheet collectionSheet = _collectionSheetRepository .FirstOrDefault(x => x.Id == sheet.CollectionCar.CollectionSheet.Id); DateTime dateCompare = lastOfThisMonth.AddDays(-DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month)).Date; if (day >= 10 && collectionSheet.TransactionDate.Value.Date <= dateCompare) { throw new UserException(ErrorStatusReturn.OVERDUE_DATE_ALLOWED_UPDATE_INFO_CUSTOMER); } }
public InfoCustomerDTO Create(CollectionSheetRequestDTO sheet) { //IsExistedTransaction(input); //IsPlateNumberHaveCollectionInThreeYear(input); //if (input.Cars.Any()) //{ // InsertListCarDTO(_carRepository, input.Cars); // InfoCustomer infoCustomer = Mapper.Map<InfoCustomerDTO, InfoCustomer>(input); // _inforCustomerRepository.Add(infoCustomer); //} //_unitOfWork.Commit(); return(new InfoCustomerDTO());; }
public CreateCollectionSheetReturnDTO Create(CollectionSheetRequestDTO sheet) { SetCustomerInfoToCar(sheet); FormatDataCustomerBeforeInsert(sheet); InactiveOldCarWhenCreate(sheet); InactiveOldInfoCustomerWhenCreate(sheet); SetStatusAndMasterDataForCollectionSheet(sheet); sheet.CollectionCar.CollectionSheet = Mapper.Map <CollectionSheetDTO>(sheet); FormatDataCollectionCarAndSheet(sheet); InsertCollectionCar(sheet.CollectionCar); _unitOfWork.Commit(); return(Mapper.Map <CreateCollectionSheetReturnDTO>(sheet)); }
public async Task <ApiJsonResult> Create([FromBody] CollectionSheetRequestDTO sheet) { try { ValidateRequestCreate(sheet); AssignCreatedByCurrentUserProfileIdInCollectionModel(sheet); await CreateTransactionCode(sheet); CreateCollectionSheetReturnDTO statusInsert = _collectionSheetService.Create(sheet); return(new ApiJsonResult(true, statusInsert)); } catch (Exception ex) { return(ProcessException(ex)); } }
private void InactiveOldInfoCustomer(CollectionSheetRequestDTO sheet) { List <InfoCustomer> listInforCustomer = _infoCustomerRepository.FindAll() .Where(x => sheet.InfoCustomer.CustomerPhone == x.CustomerPhone && sheet.InfoCustomer.IdentityNumber == x.IdentityNumber).ToList(); listInforCustomer.ForEach(x => { x.Status = Status.InActive; _infoCustomerRepository.Update(x); }); if (!listInforCustomer.Select(x => x.Id).Contains(sheet.InfoCustomer.Id)) { InfoCustomer infoCustomer = _infoCustomerRepository.FirstOrDefault(x => x.Id == sheet.InfoCustomerId); if (infoCustomer != null) { infoCustomer.Status = Status.InActive; _infoCustomerRepository.Update(infoCustomer); } } }
private void FormatDataBeforeUpdating(CollectionSheetRequestDTO sheet) { sheet.ReferenceId = sheet.CollectionCar.CollectionSheet.Id; sheet.CollectionCar.CollectionSheet.Id = 0; sheet.CollectionCar.Id = 0; sheet.InfoCustomer.Id = 0; sheet.InfoCustomerId = 0; sheet.CollectionCar.CollectionSheetId = 0; sheet.CollectionCar.CollectionSheet.InfoCustomer.Id = 0; sheet.CollectionCar.UpdatedDate = DateTime.Now; sheet.CollectionCar.CollectionSheet.UpdatedDate = DateTime.Now; if (sheet.CollectionCar.CollectionCarDetails.Any()) { sheet.CollectionCar.CollectionCarDetails.ForEach(x => { x.Id = 0; x.Car.Id = 0; x.Car.UpdatedBy = sheet.UserCreateId; x.CarId = 0; x.CollectionCarId = 0; x.UpdatedDate = DateTime.Now; }); } }
public CollectionSheetRequestDTO GetById(long id) { CollectionSheet collectionSheet = _collectionSheetRepository.FindById(id, n => n.InfoCustomer, n => n.TypeCollectionInfor); if (collectionSheet == null) { throw new UserException(ErrorStatusReturn.COLLECTION_SHEET_NOT_FOUND); } CollectionSheetRequestDTO resultCollection = Mapper.Map <CollectionSheetRequestDTO>(collectionSheet); CollectionCar collectionCar = _collectionCarRepository.FirstOrDefault(x => x.CollectionSheetId == id); if (collectionCar == null) { throw new UserException(ErrorStatusReturn.COLLECTION_SHEET_CAR_NOT_FOUND); } var collectionCarDetails = _collectionCarDetailRepository .FindAll(x => x.CollectionCarId == collectionCar.Id, x => x.Car).ProjectTo <CollectionCarDetailDTO>().ToList(); resultCollection.CollectionCar = Mapper.Map <CollectionCarDTO>(collectionCar); resultCollection.CollectionCar.CollectionCarDetails = collectionCarDetails; return(resultCollection); }
private void FormatDataCollectionCarAndSheet(CollectionSheetRequestDTO sheet) { sheet.CollectionCar.Status = Status.Active; sheet.CollectionCar.CollectionSheet.CreatedBy = sheet.InfoCustomer.CreatedBy; sheet.CollectionCar.CollectionSheet.Status = Status.Active; }
private void SetStatusForUpdateCollectionSheet(CollectionSheetRequestDTO sheet) { sheet.BriefStatus = BriefStatus.SUCCESS; sheet.BriefType = BriefType.NEW_BRIEF; }
private async Task CreateTransactionCode(CollectionSheetRequestDTO sheet) { sheet.TransactionCode = await _typeCollectionInforService.GenerateTransactionCodeByTypeCollectionId(1); }
private void AssignCreatedByCurrentUserProfileIdInCollectionModel(CollectionSheetRequestDTO sheet) { sheet.InfoCustomer.CreatedBy = GetCurrentUserProfileId(); sheet.CollectionCar.CreatedBy = GetCurrentUserProfileId(); }