private CommodityProducerDTO Map(tblCommodityProducer tbl) { var dto = new CommodityProducerDTO { MasterId = tbl.Id, DateCreated = tbl.IM_DateCreated, DateLastUpdated = tbl.IM_DateLastUpdated, StatusId = tbl.IM_Status, Code = tbl.Code, Acrage = tbl.Acrage, Name = tbl.Name, RegNo = tbl.RegNo, PhysicalAddress = tbl.PhysicalAddress, Description = tbl.Description, CommoditySupplierId = tbl.CostCentreId }; return dto; }
public CommodityProducer Map(CommodityProducerDTO dto) { if (dto == null) return null; var commodityProducer = Mapper.Map<CommodityProducerDTO, CommodityProducer>(dto); commodityProducer.CommoditySupplier = _commoditySupplierRepository.GetById(dto.CommoditySupplierId) as CommoditySupplier; return commodityProducer; }
public async Task<ResponseBool> CommodityProducerAddAsync(CommodityProducerDTO commodityProducerdto) { ResponseBool _response = new ResponseBool { Success = false, ErrorInfo = "" }; string url = string.Format("api/pushmasterdata/commodityproducer/save"); var httpClient = setupHttpClient(); httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); try { var response = await httpClient.PostAsJsonAsync(url, commodityProducerdto); var _responseBasic = await response.Content.ReadAsAsync<ResponseBasic>(); if (_responseBasic != null && _responseBasic.ErrorInfo == "OK") { _response = new ResponseBool { Success = true }; } else { _response = new ResponseBool { Success = false, ErrorInfo = _responseBasic.ErrorInfo ?? "" }; } } catch (Exception ex) { _response.ErrorInfo = "Error: An error occurred when editing the commodity supplier.\nCause: " + ex.Message; _log.Error("Failed to edit commodity supplier.", ex); } return _response; }
private void ChangeAllocation(CommodityProducerDTO dto) { CommodityProducer entity = new CommodityProducer(dto.MasterId); using (var container = NestedContainer) { var centreRepository = Using<ICentreRepository>(container); //var _commodityProducerRepository = Using<ICommodityProducerRepository>(container); var masterDataAllocationRepository = Using<IMasterDataAllocationRepository>(container); foreach (var centreId in dto.CenterIds) { entity.CommodityProducerCentres.Add(centreRepository.GetById(centreId)); } try { //_commodityProducerRepository.Save(entity); var existingAllocationForThisProducer = masterDataAllocationRepository.GetByAllocationType( MasterDataAllocationType.CommodityProducerCentreAllocation) .Where(n => n.EntityAId == entity.Id); var unallocated = existingAllocationForThisProducer.Where( n => entity.CommodityProducerCentres.Select(c => c.Id).All(cId => n.EntityBId != cId)); //foreach (var centre in entity.CommodityProducerCentres) //{ // var allocation = new MasterDataAllocation(Guid.NewGuid()) // { // _Status = EntityStatus.Active, // AllocationType = // MasterDataAllocationType.CommodityProducerCentreAllocation, // EntityAId = entity.Id, // EntityBId = centre.Id // }; // _masterDataAllocationRepository.Save(allocation); //} foreach (var allocation in unallocated) { masterDataAllocationRepository.DeleteAllocation(allocation.Id); } } catch (Exception) { //throw ; //response.ErrorInfo = "Error: An error occurred when saving the commodity producer.\n" + // ex.ToString(); } } }