public Route CreateRoute(Region region, string name, string code, Guid id) { if (region == null || region.Id == Guid.Empty) throw new ArgumentException("Invalid region assigned to route."); Route route = new Route(id) { Code = code, Name = name, Region = region, }; return route; }
public void Save(RegionViewModel region) { Region reg = new Region(region.Id) { Name = region.Name, Description=region.Description, Country=_countryRepository.GetById( region.CountryId), //districtId=_districtRepository.GetById(region.DistrictId), // provinceId=_provinceRepository.GetById(region.ProvinceId) }; _regionRepository.Save(reg); }
RegionViewModel Map(Region region) { return new RegionViewModel { Name=region.Name, Description=region.Description, isActive = region._Status == EntityStatus.Active ? true : false, CountryId=region.Country.Id, CountryName=region.Country.Name, Id=region.Id //ProvinceId=region.provinceId.Id, // DistrictId=region.districtId.Id }; }
private void AssertRegion(Region province, Region savedProvince) { Assert.AreEqual(province.Name, savedProvince.Name); Assert.AreEqual(province.Description, savedProvince.Description); Assert.AreEqual(province.Country, savedProvince.Country); Assert.AreEqual(province._Status, EntityStatus.Active); }
public RegionDTO Map(Region region) { if (region == null) return null; return Mapper.Map<Region, RegionDTO>(region); }
public static Region Map(this tblRegion region) { Region reg = new Region(region.id) { Name = region.Name, Description = region.Description, }; reg._SetDateCreated(region.IM_DateCreated); reg._SetDateLastUpdated(region.IM_DateLastUpdated); reg._SetStatus((EntityStatus)region.IM_Status); return reg; }
public bool CheckAgriRegionIsUsed(Region region, EntityStatus intendedStatus) { if (intendedStatus == EntityStatus.Inactive) { if (_ctx.tblRoutes.Any(n => n.RegionId == region.Id && n.IM_Status == (int) EntityStatus.Active)) return true; if ( _ctx.tblCostCentre.Any( n => n.Distributor_RegionId == region.Id && n.IM_Status == (int) EntityStatus.Active)) return true; } else if (intendedStatus == EntityStatus.Deleted) { if (_ctx.tblRoutes.Any(n => n.RegionId == region.Id && (n.IM_Status == (int) EntityStatus.Active || n.IM_Status == (int) EntityStatus.Inactive))) return true; if (_ctx.tblCostCentre.Any(n => n.Distributor_RegionId == region.Id && (n.IM_Status == (int) EntityStatus.Active || n.IM_Status == (int) EntityStatus.Inactive))) return true; } return false; }
protected Guid AddRegion(string name, string desc, Guid country) { Region reg = new Region(Guid.NewGuid()) { Name = name, Description = desc, Country = _countryRepository.GetById(country), }; return _regionRepository.Save(reg); }
private Region Map(RegionImport regionImport, List<string> mappingvalidationList) { var exists = Queryable.FirstOrDefault(_context.tblRegion, p => p.Name == regionImport.Code); Guid id = exists != null ? exists.id : Guid.NewGuid(); var country = Queryable.FirstOrDefault(_context.tblCountry, p => p.Code == regionImport.CountryCode); if(country==null) {mappingvalidationList.Add(string.Format((string) "Invalid Country Code {0}",(object) regionImport.CountryCode));} var countryId = country != null ? country.id : Guid.Empty; var countryEntity = _countryRepository.GetById(countryId); var region = new Region(id); region.Country = countryEntity; region.Name = regionImport.Code; region.Description = regionImport.Name; return region; }
private ValidationResultInfo Validate(Region region) { return _regionRepository.Validate(region); }
private Outlet[] ContsructEntities(IEnumerable<OutletImport> entities) { var temp = new List<Outlet>(); var defaultDistributr =ObjectFactory.GetInstance<ICostCentreRepository>() .GetByCode("PZ Cussons EA", CostCentreType.Distributor); var allRoutes = ObjectFactory.GetInstance<IRouteRepository>().GetAll().ToList(); var outletCategories = ObjectFactory.GetInstance<IOutletCategoryRepository>().GetAll().ToList(); foreach (var importentity in entities) { var domainEntity = ObjectFactory.GetInstance<ICostCentreRepository>().GetByCode(importentity.OutletCode, CostCentreType.Outlet, true) as Outlet; bool IsNew = false; if(domainEntity==null) { domainEntity = new Outlet(Guid.NewGuid()); IsNew = true; } #region Routes if (domainEntity != null && domainEntity.Route == null) { domainEntity.Route = allRoutes.FirstOrDefault( p => p.Name != null && p.Name.ToLower().Trim() == importentity.RouteName.Trim().ToLower()); } if (domainEntity.Route != null && !string.IsNullOrEmpty(importentity.RouteName)) { var newRoute = allRoutes.FirstOrDefault(p => p.Name.Trim().ToLower() == importentity.RouteName.Trim().ToLower()); if (newRoute != null) domainEntity.Route = newRoute; } if (domainEntity.Route == null && importentity.RouteName.StartsWith("SALES VA")) domainEntity.Route = allRoutes.FirstOrDefault(p => p.Name.Contains("SALES VA")); if (domainEntity.Route == null && !string.IsNullOrEmpty(importentity.RouteName)) { var region = ObjectFactory.GetInstance<IRegionRepository>().GetAll(true).FirstOrDefault(p => p.Name == "Region A"); if (region == null) { region = new Region(Guid.NewGuid()) { Country = ObjectFactory.GetInstance<ICountryRepository>().GetAll(true).FirstOrDefault(p => p.Name == "Kenya"), Name = "", Description = "" }; try { ObjectFactory.GetInstance<IRegionRepository>().Save(region); } catch { } } var route = new Route(Guid.NewGuid()) { Name = importentity.RouteName, Code = importentity.RouteName, Region = region }; try { ObjectFactory.GetInstance<IRouteRepository>().Save(route); } catch { } domainEntity.Route = route; } try { ObjectFactory.GetInstance<IRouteRepository>().Save(domainEntity.Route); } catch { } #endregion if (defaultDistributr == null) throw new ArgumentNullException("distributor"); domainEntity.ParentCostCentre = new CostCentreRef() { Id = defaultDistributr.Id }; if (domainEntity.OutletCategory == null) { OutletCategory category = outletCategories .FirstOrDefault( s => s.Name != null && s.Name == "defaultoutletcategory"); if (category == null) { category = new OutletCategory(Guid.NewGuid()) { Name = string.IsNullOrEmpty(importentity.Name) ? "defaultoutletcategory" : importentity.Name, Code = string.IsNullOrEmpty(importentity.Name) ? "defaultoutletcategory" : importentity.Name }; try { ObjectFactory.GetInstance<IOutletCategoryRepository>().Save(category,true); } catch { } } domainEntity.OutletCategory = category; } if (domainEntity.OutletType == null) { OutletType type =ObjectFactory.GetInstance<IOutletTypeRepository>().GetAll(true).FirstOrDefault( p => p.Name != null && p.Name == "defaultoutlettype"); if (type == null) { type = new OutletType(Guid.NewGuid()) { Name = string.IsNullOrEmpty(importentity.Name) ? "defaultoutlettype" : importentity.Name, Code = string.IsNullOrEmpty(importentity.Name) ? "defaultoutlettype" : importentity.Name }; try { ObjectFactory.GetInstance<IOutletTypeRepository>().Save(type); } catch { } } domainEntity.OutletType = type; } if (domainEntity.OutletProductPricingTier == null) { ProductPricingTier tire =ObjectFactory.GetInstance<IProductPricingTierRepository>() .GetAll(true).FirstOrDefault( p => p.Code != null && p.Code.Trim() == importentity.Currency.Trim()); if (tire == null) { tire = new ProductPricingTier(Guid.NewGuid()) { Name = importentity.Currency.Trim(), Code = importentity.Currency.Trim(), Description = importentity.Currency.Trim(), }; try { ObjectFactory.GetInstance<IProductPricingTierRepository>().Save(tire); } catch { } } domainEntity.OutletProductPricingTier = tire; } if (domainEntity.VatClass == null) { VATClass productVat = ObjectFactory.GetInstance<IVATClassRepository>().GetAll(true). FirstOrDefault( p => p.Name != null && p.Name == "defaultVAT"); if (productVat == null) { var viatItem = new VATClass.VATClassItem(Guid.NewGuid()) { EffectiveDate = DateTime.Now, Rate = 0, }; productVat = new VATClass(Guid.NewGuid()) { Name = "defaultVAT", VatClass = "defaultVAT", }; productVat.VATClassItems.Add(viatItem); try { ObjectFactory.GetInstance<IVATClassRepository>().Save(productVat); } catch { } } domainEntity.VatClass = productVat; } domainEntity._Status =EntityStatus.Active; //GetStatus(importentity.Status); domainEntity.Name = importentity.Name.Trim(); domainEntity.CostCentreCode = importentity.OutletCode.Trim(); temp.Add(domainEntity); } return temp.ToArray(); }