public async Task <MerchantAddressDto> Handle(AddMerchantAddressCommand request, CancellationToken cancellationToken) { var merchant = await _merchantRepository.GetAsync(request.MerchantCode); if (merchant is null) { throw new MerchantNotFoundException(); } var merchantLocation = MerchantAddress.RegisterCreated( request.MerchantCode, request.MerchantName, request.Name, request.Address, request.Country, request.City, request.Town, request.District, request.Location, request.WorkingHours, request.ExtraInfo); merchantLocation.Activate(); var locations = await _merchantLocationsRepository.GetAsync(request.MerchantCode, request.Name); if (locations != null) { throw new MerchantAddressAlreadyRegisteredException(); } await _merchantLocationsRepository.AddAsync(merchantLocation); return(_mapper.Map <MerchantAddressDto>(merchantLocation)); }
public async Task <MerchantAddress> Delete(MerchantAddress MerchantAddress) { if (!await MerchantAddressValidator.Delete(MerchantAddress)) { return(MerchantAddress); } try { await UOW.Begin(); await UOW.MerchantAddressRepository.Delete(MerchantAddress); await UOW.Commit(); await UOW.AuditLogRepository.Create("", MerchantAddress, nameof(MerchantAddressService)); return(MerchantAddress); } catch (Exception ex) { await UOW.Rollback(); await UOW.SystemLogRepository.Create(ex, nameof(MerchantAddressService)); throw new MessageException(ex); } }
public async Task <bool> Delete(MerchantAddress MerchantAddress) { if (await ValidateId(MerchantAddress)) { } return(MerchantAddress.IsValidated); }
public async Task <MerchantAddress> Update(MerchantAddress MerchantAddress) { if (!await MerchantAddressValidator.Update(MerchantAddress)) { return(MerchantAddress); } try { var oldData = await UOW.MerchantAddressRepository.Get(MerchantAddress.Id); await UOW.Begin(); await UOW.MerchantAddressRepository.Update(MerchantAddress); await UOW.Commit(); var newData = await UOW.MerchantAddressRepository.Get(MerchantAddress.Id); await UOW.AuditLogRepository.Create(newData, oldData, nameof(MerchantAddressService)); return(newData); } catch (Exception ex) { await UOW.Rollback(); await UOW.SystemLogRepository.Create(ex, nameof(MerchantAddressService)); throw new MessageException(ex); } }
public MerchantMaster_MerchantAddressDTO(MerchantAddress MerchantAddress) { this.Id = MerchantAddress.Id; this.MerchantId = MerchantAddress.MerchantId; this.Code = MerchantAddress.Code; this.Address = MerchantAddress.Address; this.Contact = MerchantAddress.Contact; this.Phone = MerchantAddress.Phone; }
public async Task <bool> Delete(MerchantAddress MerchantAddress) { MerchantAddressDAO MerchantAddressDAO = await DataContext.MerchantAddress.Where(x => x.Id == MerchantAddress.Id).FirstOrDefaultAsync(); DataContext.MerchantAddress.Remove(MerchantAddressDAO); await DataContext.SaveChangesAsync(); return(true); }
public async Task <MerchantAddress> Get(long Id) { MerchantAddress MerchantAddress = await UOW.MerchantAddressRepository.Get(Id); if (MerchantAddress == null) { return(null); } return(MerchantAddress); }
public async Task <MerchantAddressDetail_MerchantAddressDTO> Get([FromBody] MerchantAddressDetail_MerchantAddressDTO MerchantAddressDetail_MerchantAddressDTO) { if (!ModelState.IsValid) { throw new MessageException(ModelState); } MerchantAddress MerchantAddress = await MerchantAddressService.Get(MerchantAddressDetail_MerchantAddressDTO.Id); return(new MerchantAddressDetail_MerchantAddressDTO(MerchantAddress)); }
public MerchantAddress ConvertDTOToEntity(MerchantAddressDetail_MerchantAddressDTO MerchantAddressDetail_MerchantAddressDTO) { MerchantAddress MerchantAddress = new MerchantAddress(); MerchantAddress.Id = MerchantAddressDetail_MerchantAddressDTO.Id; MerchantAddress.MerchantId = MerchantAddressDetail_MerchantAddressDTO.MerchantId; MerchantAddress.Code = MerchantAddressDetail_MerchantAddressDTO.Code; MerchantAddress.Address = MerchantAddressDetail_MerchantAddressDTO.Address; MerchantAddress.Contact = MerchantAddressDetail_MerchantAddressDTO.Contact; MerchantAddress.Phone = MerchantAddressDetail_MerchantAddressDTO.Phone; return(MerchantAddress); }
public MerchantAddressDetail_MerchantAddressDTO(MerchantAddress MerchantAddress) { this.Id = MerchantAddress.Id; this.MerchantId = MerchantAddress.MerchantId; this.Code = MerchantAddress.Code; this.Address = MerchantAddress.Address; this.Contact = MerchantAddress.Contact; this.Phone = MerchantAddress.Phone; this.Merchant = new MerchantAddressDetail_MerchantDTO(MerchantAddress.Merchant); }
public async Task <bool> Update(MerchantAddress MerchantAddress) { MerchantAddressDAO MerchantAddressDAO = DataContext.MerchantAddress.Where(x => x.Id == MerchantAddress.Id).FirstOrDefault(); MerchantAddressDAO.Id = MerchantAddress.Id; MerchantAddressDAO.MerchantId = MerchantAddress.MerchantId; MerchantAddressDAO.Code = MerchantAddress.Code; MerchantAddressDAO.Address = MerchantAddress.Address; MerchantAddressDAO.Contact = MerchantAddress.Contact; MerchantAddressDAO.Phone = MerchantAddress.Phone; await DataContext.SaveChangesAsync(); return(true); }
public async Task <bool> Create(MerchantAddress MerchantAddress) { MerchantAddressDAO MerchantAddressDAO = new MerchantAddressDAO(); MerchantAddressDAO.Id = MerchantAddress.Id; MerchantAddressDAO.MerchantId = MerchantAddress.MerchantId; MerchantAddressDAO.Code = MerchantAddress.Code; MerchantAddressDAO.Address = MerchantAddress.Address; MerchantAddressDAO.Contact = MerchantAddress.Contact; MerchantAddressDAO.Phone = MerchantAddress.Phone; await DataContext.MerchantAddress.AddAsync(MerchantAddressDAO); await DataContext.SaveChangesAsync(); MerchantAddress.Id = MerchantAddressDAO.Id; return(true); }
public async Task <ActionResult <MerchantAddressDetail_MerchantAddressDTO> > Update([FromBody] MerchantAddressDetail_MerchantAddressDTO MerchantAddressDetail_MerchantAddressDTO) { if (!ModelState.IsValid) { throw new MessageException(ModelState); } MerchantAddress MerchantAddress = ConvertDTOToEntity(MerchantAddressDetail_MerchantAddressDTO); MerchantAddress = await MerchantAddressService.Update(MerchantAddress); MerchantAddressDetail_MerchantAddressDTO = new MerchantAddressDetail_MerchantAddressDTO(MerchantAddress); if (MerchantAddress.IsValidated) { return(MerchantAddressDetail_MerchantAddressDTO); } else { return(BadRequest(MerchantAddressDetail_MerchantAddressDTO)); } }
public async Task <bool> ValidateId(MerchantAddress MerchantAddress) { MerchantAddressFilter MerchantAddressFilter = new MerchantAddressFilter { Skip = 0, Take = 10, Id = new LongFilter { Equal = MerchantAddress.Id }, Selects = MerchantAddressSelect.Id }; int count = await UOW.MerchantAddressRepository.Count(MerchantAddressFilter); if (count == 0) { MerchantAddress.AddError(nameof(MerchantAddressValidator), nameof(MerchantAddress.Id), ErrorCode.IdNotExisted); } return(count == 1); }
public async Task <MerchantAddress> Get(long Id) { MerchantAddress MerchantAddress = await DataContext.MerchantAddress.Where(x => x.Id == Id).Select(MerchantAddressDAO => new MerchantAddress() { Id = MerchantAddressDAO.Id, MerchantId = MerchantAddressDAO.MerchantId, Code = MerchantAddressDAO.Code, Address = MerchantAddressDAO.Address, Contact = MerchantAddressDAO.Contact, Phone = MerchantAddressDAO.Phone, Merchant = MerchantAddressDAO.Merchant == null ? null : new Merchant { Id = MerchantAddressDAO.Merchant.Id, Name = MerchantAddressDAO.Merchant.Name, Phone = MerchantAddressDAO.Merchant.Phone, ContactPerson = MerchantAddressDAO.Merchant.ContactPerson, Address = MerchantAddressDAO.Merchant.Address, }, }).FirstOrDefaultAsync(); return(MerchantAddress); }
public async Task UpdateAsync(MerchantAddress merchantAddress) { var filter = Builders <MerchantAddress> .Filter.Eq(x => x.Code, merchantAddress.Code) & Builders <MerchantAddress> .Filter.Eq(x => x.MerchantCode, merchantAddress.MerchantCode); var update = Builders <MerchantAddress> .Update .Set(x => x.IsActive, merchantAddress.IsActive) .Set(x => x.Address, merchantAddress.Address) .Set(x => x.City, merchantAddress.City) .Set(x => x.Country, merchantAddress.Country) .Set(x => x.District, merchantAddress.District) .Set(x => x.ExtraInfo, merchantAddress.ExtraInfo) .Set(x => x.LastChangeTime, merchantAddress.LastChangeTime) .Set(x => x.Location, merchantAddress.Location) .Set(x => x.State, merchantAddress.State) .Set(x => x.Town, merchantAddress.Town) .Set(x => x.State, merchantAddress.State) .Set(x => x.WorkingHours, merchantAddress.WorkingHours) .Set(x => x.Name, merchantAddress.Name) .Set(x => x.AvailableLocations, merchantAddress.AvailableLocations); var result = await _mongoDbContext.MerchantAddresses.UpdateOneAsync(filter, update); }
public async Task AddAsync(MerchantAddress merchantLocation) { await _mongoDbContext.MerchantAddresses.InsertOneAsync(merchantLocation); }
public async Task <bool> Create(MerchantAddress MerchantAddress) { return(MerchantAddress.IsValidated); }