public NOPVData SaveDetails(NOPVData data) { NOPVData nopvObject = dbContext.NOPVDatas.Add(data); dbContext.SaveChanges(); return(nopvObject); }
public NOPVData GetDetails(string bbl) { //var query = dbContext.Database.SqlQuery<NOPVData>("select * from \"NOPVData\" where \"BBL\"=@bbl", new NpgsqlParameter("bbl", bbl)); //string querytxt = "select * from \"NOPVData\" where \"BBL\" = '" + bbl + "'"; //var query = dbContext.NOPVDatas.SqlQuery(querytxt).FirstOrDefault(); //NOPVData entity = query; NOPVData entity = dbContext.NOPVDatas.FirstOrDefault(e => e.BBL == bbl); if (entity == null) { throw new Exception("BBL not found"); } return(entity); }
public NOPVData UpdateDetails(string bbl, JsonPatch.JsonPatchDocument <NOPVData> data) { NOPVData entity = dbContext.NOPVDatas.FirstOrDefault(b => b.BBL == bbl); if (entity == null) { throw new Exception("BBL not found"); } try { //dbContext.Entry(entity).CurrentValues.SetValues(data); data.ApplyUpdatesTo(entity); //dbContext.Entry(entity).State = System.Data.Entity.EntityState.Modified; dbContext.SaveChanges(); return(entity); } catch (Exception ex) { throw new Exception("Error while updating data", ex); } }