示例#1
0
        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);
                }
            }
        }
示例#2
0
 protected void Initialise()
 {
     this.regionEntities = RegionEntities.GetInstance();
     SetFriendlyNPCs();
     SetEnemies();
     SetGateways();
     SetObstacles();
     SetBoostItems();
 }
示例#3
0
 public List <ZipModel> ZipFindAll()
 {
     using (RegionEntities re = new RegionEntities())
     {
         return(re.Zips.Select(z => new ZipModel
         {
             ZipCode = z.ZipCode
         }).ToList());
     }
 }
示例#4
0
 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());
     }
 }
示例#5
0
 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());
     }
 }
示例#6
0
 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);
         }
     }
 }
示例#7
0
        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);
                }
            }
        }