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)); }
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)); }