public GradeValuesResult editGradeValue(int gradeId, int registrationId, string value, byte[] currentTimeStamp) { using (var db = new NTR2013Entities()) { var original = db.GradeValues.Where(g => g.GradeID == gradeId && g.RegistrationID == registrationId).ToList().ElementAt(0); if (!compareTimeStamp(original.TimeStamp, currentTimeStamp)) { GradeValuesResult result = new GradeValuesResult(ErrorMessage.REMOVE_GRADES_CONCURRENCY); GradeValues grade = new GradeValues { GradeValueID = original.GradeValueID, GradeID = original.GradeID, RegistrationID = original.RegistrationID, Date = original.Date, Value = original.Value, TimeStamp = original.TimeStamp, Grades = null, Registrations = null }; result.data = grade; return(result); } //db.GradeValues.Remove(original); original.Value = value; db.SaveChanges(); GradeValues current = new GradeValues { GradeValueID = original.GradeValueID, GradeID = original.GradeID, RegistrationID = original.RegistrationID, Date = original.Date, Value = original.Value, TimeStamp = original.TimeStamp, Grades = null, Registrations = null }; return(new GradeValuesResult(current)); } }
public GradeValuesResult editGradeValue(int gradeId, int registrationId, string value, byte[] currentTimeStamp) { using (var db = new NTR2013Entities()) { var original = db.GradeValues.Where(g => g.GradeID == gradeId && g.RegistrationID == registrationId).ToList().ElementAt(0); if (!compareTimeStamp(original.TimeStamp, currentTimeStamp)) { GradeValuesResult result = new GradeValuesResult(ErrorMessage.REMOVE_GRADES_CONCURRENCY); GradeValues grade = new GradeValues { GradeValueID = original.GradeValueID, GradeID = original.GradeID, RegistrationID = original.RegistrationID, Date = original.Date, Value = original.Value, TimeStamp = original.TimeStamp, Grades = null, Registrations = null }; result.data = grade; return result; } //db.GradeValues.Remove(original); original.Value = value; db.SaveChanges(); GradeValues current = new GradeValues { GradeValueID = original.GradeValueID, GradeID = original.GradeID, RegistrationID = original.RegistrationID, Date = original.Date, Value = original.Value, TimeStamp = original.TimeStamp, Grades = null, Registrations = null }; return new GradeValuesResult(current); } }