public HttpResponseMessage UpdateParameters(string key, string value, string ConnectionString) { try { using (ThomsonDbContext db = new ThomsonDbContext(ConnectionString)) { Parameter objParameter = db.Parameters.FirstOrDefault(m => m.Name == key); objParameter.Value = value; db.Entry(objParameter).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(new HttpResponseMessage() { Content = new StringContent("successfully Updated") }); } } catch (Exception ex) { Log.Error(ex.Message); throw ex; } }
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)); }