Пример #1
0
 public IHttpActionResult Update([FromBody] RegDetailViewModel databody)
 {
     using (var db = new DB_Context())
     {
         try
         {
             Dictionary <string, object> result    = new Dictionary <string, object>();
             List <RegDetailViewModel>   regUpdate = new List <RegDetailViewModel>();
             Region region = db.Regions.Find(databody.RegionID);
             databody.updateRegion(region);
             var reg = db.Regions.Where(data => data.RegionID == databody.RegionID).AsEnumerable().ToList();
             foreach (var item in reg)
             {
                 RegDetailViewModel regView = new RegDetailViewModel(item);
                 regUpdate.Add(regView);
             }
             db.SaveChanges();
             result.Add("Data", regUpdate);
             return(Ok(result));
         }
         catch (Exception)
         {
             throw;
         }
     }
 }
Пример #2
0
        public IHttpActionResult Create([FromBody] RegDetailViewModel databody)
        {
            using (var db = new DB_Context())
            {
                try
                {
                    Dictionary <string, object> result     = new Dictionary <string, object>();
                    List <RegDetailViewModel>   listRegion = new List <RegDetailViewModel>();
                    var temp = databody.convertToRegion();
                    db.Regions.Add(temp);
                    db.SaveChanges();
                    var reg = db.Regions.Where(data => data.RegionID == databody.RegionID).AsEnumerable().ToList();
                    foreach (var item in reg)
                    {
                        RegDetailViewModel regView = new RegDetailViewModel(item);
                        listRegion.Add(regView);
                    }

                    databody.insTeritory(db);
                    result.Add("Data", listRegion);
                    return(Ok(result));
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }