public IHttpActionResult ReadAll(int?regID = null)
 {
     using (var db = new DB_Context())
     {
         try
         {
             RegionDetailViewModel listResult        = new RegionDetailViewModel();
             var listRegionEntity                    = db.Regions.AsQueryable();
             List <RegionDetailViewModel> listRegion = new List <RegionDetailViewModel>();
             if (regID != null)
             {
                 listRegionEntity = listRegionEntity.Where(data => data.RegionID == regID);
             }
             foreach (var item in listRegionEntity.AsEnumerable().ToList())
             {
                 RegionDetailViewModel region = new RegionDetailViewModel(item);
                 listRegion.Add(region);
             }
             Dictionary <string, object> finalReturn = listResult.FinalResult(listRegion, "Read Data Success");
             return(Ok(finalReturn));
         }
         catch (Exception)
         {
             throw;
         }
     }
 }
 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;
         }
     }
 }
 public IHttpActionResult Create([FromBody] RegionDetailViewModel dataBody)
 {
     using (var db = new DB_Context())
     {
         try
         {
             Dictionary <string, object>  result     = new Dictionary <string, object>();
             List <RegionDetailViewModel> listDetail = new List <RegionDetailViewModel>();
             var temp = dataBody.convertToRegion();
             db.Regions.Add(temp);
             db.SaveChanges();
             var regTemp = db.Regions.Where(dt => dt.RegionID == dataBody.RegionID).AsEnumerable().ToList();
             RegionDetailViewModel regView = new RegionDetailViewModel(regTemp);
             listDetail.Add(regView);
             result.Add("data region", listDetail);
             dataBody.InputData(db);
             return(Ok(result));
         }
         catch (Exception)
         {
             throw;
         }
     }
 }