public IHttpActionResult ReadAll(int?regionID = null)
 {
     using (var DB = new DB_Context())
     {
         try
         {
             var tem = DB.Regions.AsQueryable();
             RegionDetailViewModel        regionObj  = new RegionDetailViewModel();
             List <RegionDetailViewModel> listRegion = new List <RegionDetailViewModel>();
             if (regionID != null)
             {
                 tem = tem.Where(data => data.RegionID == regionID);
             }
             var listRegionEntity = tem.AsEnumerable().ToList();
             foreach (var item in listRegionEntity)
             {
                 RegionDetailViewModel region = new RegionDetailViewModel(item);
                 listRegion.Add(region);
             }
             return(Ok(regionObj.finalResult(listRegion, "Read Data Success")));
         }
         catch (Exception)
         {
             throw;
         }
     }
 }
 public IHttpActionResult Update([FromBody] RegionDetailViewModel dataBody)
 {
     using (var db = new DB_Context())
     {
         try
         {
             List <RegionDetailViewModel> listRegion = new List <RegionDetailViewModel>();
             Region region             = db.Regions.Find(dataBody.RegionID);
             var    temp               = dataBody.convertToRegion2(region);
             RegionDetailViewModel reg = new RegionDetailViewModel(temp);
             listRegion.Add(reg);
             db.SaveChanges();
             return(Ok(dataBody.finalResult(listRegion, "Update Data Success")));
         }
         catch (Exception)
         {
             throw;
         }
     }
 }
 public IHttpActionResult Create([FromBody] RegionDetailViewModel dataBody)
 {
     using (var DB = new DB_Context())
     {
         try
         {
             List <RegionDetailViewModel> listRegion = new List <RegionDetailViewModel>();
             var temp = dataBody.convertToRegion();
             DB.Regions.Add(temp);
             DB.SaveChanges();
             var reg = DB.Regions.Where(dt => dt.RegionID == dataBody.RegionID).AsEnumerable().ToList();
             RegionDetailViewModel regionView = new RegionDetailViewModel(reg);
             listRegion.Add(regionView);
             dataBody.Insertdata(DB);
             return(Ok(dataBody.finalResult(listRegion, "Insert Data Success")));
         }
         catch (Exception)
         {
             throw;
         }
     }
 }