コード例 #1
0
        public HttpResponseMessage Edit(int id, string SiteName)
        {
            List <LocationIndicatorViewModel> lstLocationIndicatorViewModel = new List <LocationIndicatorViewModel>();
            LocationIndicatorViewModel        objLocationIndicatorViewModel = new LocationIndicatorViewModel();

            objLocationIndicatorViewModel.SiteName         = SiteName;
            objLocationIndicatorViewModel.AreaOfInterestId = id;
            using (ThomsonDbContext db = new ThomsonDbContext(SiteName))
            {
                objLocationIndicatorViewModel.Name = db.InterestLocation.First(m => m.AreaOfInterestId == id).Name;
                objLocationIndicatorViewModel.LoctionIndicatorId = db.LocationIndicator.First(m => m.AreaOfInterestId == id).LoctionIndicatorId;
                foreach (var item in db.LocationIndicator.Where(m => m.AreaOfInterestId == id))
                {
                    MapLocation objMapLocation = new MapLocation();
                    objMapLocation.LoctionIndicatorId = item.LoctionIndicatorId;
                    objMapLocation.LoctionIndicator   = item.LoctionIndicator;
                    objMapLocation.AreaOfInterestId   = item.AreaOfInterestId;
                    objLocationIndicatorViewModel.lstMapLocations.Add(objMapLocation);
                }

                foreach (var item in db.NeighBourAreas.Where(m => m.AreaId == id))
                {
                    NeighBourAreaMap objNeighBourMapLocation = new NeighBourAreaMap();
                    objNeighBourMapLocation.NeighBourId      = item.NeighbourAreaId;
                    objNeighBourMapLocation.NeighBourName    = item.AreaCode.ToString();
                    objNeighBourMapLocation.AreaOfInterestId = item.AreaId;
                    objLocationIndicatorViewModel.lstNeighBourMaps.Add(objNeighBourMapLocation);
                }
            }


            lstLocationIndicatorViewModel.Add(objLocationIndicatorViewModel);
            return(Request.CreateResponse(objLocationIndicatorViewModel));
        }
コード例 #2
0
 public HttpResponseMessage DeleteLocationIndicator(LocationIndicatorViewModel objLocation)
 {
     try
     {
         using (ThomsonDbContext db = new ThomsonDbContext(objLocation.SiteName))
         {
             LocationIndicator objLocationIndicator = db.LocationIndicator.Where(b => b.LoctionIndicatorId == objLocation.LoctionIndicatorId).FirstOrDefault();
             db.LocationIndicator.Remove(objLocationIndicator);
             db.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return(Request.CreateResponse(HttpStatusCode.OK));
 }
コード例 #3
0
 public HttpResponseMessage Delete(LocationIndicatorViewModel objLocation)
 {
     try
     {
         using (ThomsonDbContext db = new ThomsonDbContext(objLocation.SiteName))
         {
             var objAreaOfInterest = db.InterestLocation.Where(a => a.AreaOfInterestId == objLocation.AreaOfInterestId).FirstOrDefault();
             db.InterestLocation.Remove(objAreaOfInterest);
             db.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return(Request.CreateResponse(HttpStatusCode.OK));
 }
コード例 #4
0
        public List <LocationIndicatorViewModel> Index(string SiteName)
        {
            //Assign the Default Site

            if (!string.IsNullOrEmpty(SiteName) || SiteName == null)
            {
                SiteName = "Discovery1";
            }
            List <LocationIndicatorViewModel> lstLocationIndicatorViewModel = new List <LocationIndicatorViewModel>();

            try
            {
                using (var db = new ThomsonDbContext(SiteName))
                {
                    var interLocationsData = db.InterestLocation.ToList();

                    foreach (var item in interLocationsData.GroupBy(m => new { m.AreaOfInterestId, m.Name }))
                    {
                        LocationIndicatorViewModel objLocationIndicatorViewModel = new LocationIndicatorViewModel();
                        objLocationIndicatorViewModel.AreaOfInterestId = item.Key.AreaOfInterestId;
                        objLocationIndicatorViewModel.Name             = item.Key.Name;

                        foreach (var item1 in db.LocationIndicator.Where(m => m.AreaOfInterestId == objLocationIndicatorViewModel.AreaOfInterestId))
                        {
                            objLocationIndicatorViewModel.LoctionIndicator += item1.LoctionIndicator + ",";
                        }
                        foreach (var item2 in db.NeighBourAreas.Where(m => m.AreaId == objLocationIndicatorViewModel.AreaOfInterestId))
                        {
                            objLocationIndicatorViewModel.NeighBourName += item2.AreaCode + ",";
                        }
                        lstLocationIndicatorViewModel.Add(objLocationIndicatorViewModel);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(lstLocationIndicatorViewModel);
        }
コード例 #5
0
        public HttpResponseMessage Create(LocationIndicatorViewModel objlocationIndicator)
        {
            InterestLocation locationModel = new InterestLocation();

            objlocationIndicator.SiteName = "Discovery1";

            using (ThomsonDbContext db = new ThomsonDbContext(objlocationIndicator.SiteName))
            {
                if (!string.IsNullOrEmpty(objlocationIndicator.Name))
                {
                    locationModel.Name = objlocationIndicator.Name;
                    db.InterestLocation.Add(locationModel);
                    db.SaveChanges();
                }

                var location = db.InterestLocation.Where(a => a.Name == locationModel.Name).SingleOrDefault();
                if (!string.IsNullOrEmpty(objlocationIndicator.LoctionIndicator))
                {
                    LocationIndicator indicatorModel = new LocationIndicator();
                    indicatorModel.LoctionIndicator = objlocationIndicator.LoctionIndicator;
                    indicatorModel.AreaOfInterestId = location.AreaOfInterestId;
                    db.LocationIndicator.Add(indicatorModel);
                }

                if (!string.IsNullOrEmpty(objlocationIndicator.NeighBourName))
                {
                    NeighBourArea objNeighBourArea = new NeighBourArea();
                    objNeighBourArea.AreaId   = location.AreaOfInterestId;
                    objNeighBourArea.AreaCode = objlocationIndicator.NeighBourName;
                    db.NeighBourAreas.Add(objNeighBourArea);
                }

                db.SaveChanges();
            }
            return(Request.CreateResponse(HttpStatusCode.OK));
        }
コード例 #6
0
        public HttpResponseMessage Edit(LocationIndicatorViewModel locationIndicator)
        {
            try
            {
                using (ThomsonDbContext db = new ThomsonDbContext(locationIndicator.SiteName))
                {
                    var objInterestLoction = db.InterestLocation.Where(p => p.AreaOfInterestId == locationIndicator.AreaOfInterestId).FirstOrDefault();
                    objInterestLoction.Name            = locationIndicator.Name;
                    db.Entry(objInterestLoction).State = EntityState.Modified;
                    //var ab = fc["LoctionIndicator"].ToString();
                    //foreach (var item in fc["LoctionIndicator"].Split(','))
                    //{
                    //    if (!string.IsNullOrEmpty(item))
                    //    {
                    //        LocationIndicator indicatorModel = new LocationIndicator();
                    //        indicatorModel.LoctionIndicator = item.ToString();
                    //        indicatorModel.AreaOfInterestId = objInterestLoction.AreaOfInterestId;
                    //        db.LocationIndicator.Add(indicatorModel);
                    //    }
                    //}

                    //foreach (var item in fc["NeighBourName"].Split(','))
                    //{
                    //    if (!string.IsNullOrEmpty(item))
                    //    {
                    //        NeighBourArea objNeighBourArea = new NeighBourArea();
                    //        objNeighBourArea.AreaCode = item;
                    //        objNeighBourArea.AreaId = locationIndicator.AreaOfInterestId;
                    //        db.NeighBourAreas.Add(objNeighBourArea);
                    //    }
                    //}

                    foreach (var Item in locationIndicator.lstMapLocations)
                    {
                        var objlocationIndicator = new LocationIndicator();
                        if (db.LocationIndicator.Any(m => m.LoctionIndicatorId == Item.LoctionIndicatorId))
                        {
                            objlocationIndicator = db.LocationIndicator.Where(m => m.AreaOfInterestId == locationIndicator.AreaOfInterestId && m.LoctionIndicatorId == Item.LoctionIndicatorId).FirstOrDefault();
                            objlocationIndicator.LoctionIndicator = Item.LoctionIndicator;
                            db.Entry(objlocationIndicator).State  = EntityState.Modified;
                        }
                        else
                        {
                            objlocationIndicator.LoctionIndicator = Item.LoctionIndicator;
                            objlocationIndicator.AreaOfInterestId = Item.AreaOfInterestId;
                            db.LocationIndicator.Add(objlocationIndicator);
                        }
                    }

                    foreach (var item in locationIndicator.lstNeighBourMaps)
                    {
                        var ObjNeighBourArea = new NeighBourArea();
                        if (db.NeighBourAreas.Any(m => m.NeighbourAreaId == item.NeighBourId))
                        {
                            ObjNeighBourArea                 = db.NeighBourAreas.Where(m => m.NeighbourAreaId == item.NeighBourId && m.AreaId == locationIndicator.AreaOfInterestId).FirstOrDefault();
                            ObjNeighBourArea.AreaCode        = item.NeighBourName;
                            db.Entry(ObjNeighBourArea).State = EntityState.Modified;
                        }
                        else
                        {
                            ObjNeighBourArea.AreaCode = item.NeighBourName;
                            ObjNeighBourArea.AreaId   = item.AreaOfInterestId;
                            db.NeighBourAreas.Add(ObjNeighBourArea);
                        }
                    }
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
            }
            return(Request.CreateResponse(HttpStatusCode.OK));
        }