public HttpResponseMessage Put(int id, [FromBody] Site site) { try { using (RadioDbContext context = new RadioDbContext()) { var entity = context.Sites.FirstOrDefault(e => e.SiteId == id); if (entity != null) { entity.Name = site.Name; entity.Address = site.Address; entity.AppNo = site.AppNo; entity.Category = site.Category; entity.City = site.City; entity.Latitude = site.Latitude; entity.Longitude = site.Longitude; entity.Post = site.Post; entity.State = site.State; context.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, entity.Name + " has been updated!")); } else { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Id " + entity.SiteId.ToString() + "Not found!")); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage Delete(int id) { try { using (RadioDbContext context = new RadioDbContext()) { var entity = context.Sites.FirstOrDefault(e => e.SiteId == id); if (entity == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Site Id =" + entity.SiteId + " was not found.")); } else { context.Sites.Remove(context.Sites.FirstOrDefault(e => e.SiteId == id)); context.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public IEnumerable <Site> GetAllSites() { RadioDbContext db = new RadioDbContext(); return(db.Sites); }
public ImgRepository(RadioDbContext db) { this.db = db; }
public SiteRepository(RadioDbContext db) { this.db = db; }