public bool create(RegionModel region) { using (RegionEntities re = new RegionEntities()) { try { Region r = new Region(); ZipCode z = new ZipCode(); r.ID = region.ID; r.Name = region.Name; z.ID = region.ID; z.Start = region.ZipCodes[0].Start; z.End = region.ZipCodes[0].End; re.Regions.Add(r); re.SaveChanges(); re.ZipCodes.Add(z); re.SaveChanges(); return(true); } catch (Exception) { return(false); } } }
protected void Initialise() { this.regionEntities = RegionEntities.GetInstance(); SetFriendlyNPCs(); SetEnemies(); SetGateways(); SetObstacles(); SetBoostItems(); }
public List <ZipModel> ZipFindAll() { using (RegionEntities re = new RegionEntities()) { return(re.Zips.Select(z => new ZipModel { ZipCode = z.ZipCode }).ToList()); } }
public RegionModel Find(string id) { using (RegionEntities re = new RegionEntities()) { return(re.RegionZipCodes.Where(reg => reg.ID == id).Select(reg => new RegionModel { ID = reg.ID, Name = reg.Name, ZipCodes = new List <ZipCodeModel> { new ZipCodeModel { Start = reg.Start, End = reg.End } } }).FirstOrDefault()); } }
public List <RegionModel> FindAll() { using (RegionEntities re = new RegionEntities()) { return(re.RegionZipCodes.Select(r => new RegionModel { ID = r.ID, Name = r.Name, ZipCodes = new List <ZipCodeModel> { new ZipCodeModel { Start = r.Start, End = r.End } } }).ToList()); } }
public bool Delete(RegionModel Region) { using (RegionEntities re = new RegionEntities()) { try { Region r = re.Regions.Single(reg => reg.ID == Region.ID); ZipCode z = re.ZipCodes.Single(zip => zip.ID == Region.ID); re.Regions.Remove(r); re.ZipCodes.Remove(z); re.SaveChanges(); return(true); } catch (Exception) { return(false); } } }
public bool Edit(RegionModel Region) { using (RegionEntities re = new RegionEntities()) { try { Region r = re.Regions.Single(reg => reg.ID == Region.ID); r.ID = Region.ID; r.Name = Region.Name; ZipCode z = re.ZipCodes.Single(zip => zip.ID == Region.ID); z.Start = Region.ZipCodes[0].Start; z.End = Region.ZipCodes[0].End; re.SaveChanges(); return(true); } catch (Exception) { return(false); } } }