public static void ValidateUser(CUser user, string authToken) { try { using (var db = new RecContext()) { var teacher = db.Teacher.Where(t => t.Email == user.EmailAddress).FirstOrDefault(); if (teacher == null) { user.ExistsOnServer = false; return; } user.ExistsOnServer = true; user.TeacherId = teacher.TeacherId; db.Update(teacher); teacher.AuthorizationToken = authToken; db.SaveChanges(); } } catch (Exception e) { var sException = new ServerException(e.Message, e, true); LogServerException(sException); } }
public static void AddNewTeacher(CTeacher teacher, int userId) { try { using (var db = new RecContext()) { var dbTeacher = new Teacher { FirstName = teacher.FirstName, LastName = teacher.LastName, Email = teacher.EmailAddress }; db.Add(dbTeacher); db.SaveChanges(); var teacherId = db.Teacher.Where(t => t.Email == teacher.EmailAddress).Select(t => t.TeacherId).First(); var recTeacher = new RecTeacher { TeacherId = teacherId, RecId = GetRecIdForUser(userId, db), IsAdministrator = teacher.IsAdministrator, }; if (teacher.IsDisabled) { recTeacher.DisableDate = DateTime.Now; } db.Add(recTeacher); foreach (CClassTerm classTerm in teacher.ClassesTaught) { db.Add(new ClassTermTeacher { ClassTermId = classTerm.ClassTermId, TeacherId = teacherId }); } db.SaveChanges(); } } catch (Exception e) { var sException = new ServerException(e.Message, e, false); LogServerException(sException); } }
public static void UpdateExistingTeacher(CTeacher teacher, int userId) { try { using (var db = new RecContext()) { var dbTeacher = db.Teacher.Where(t => t.TeacherId == teacher.TeacherId).First(); db.Update(dbTeacher); dbTeacher.FirstName = teacher.FirstName; dbTeacher.LastName = teacher.LastName; dbTeacher.Email = teacher.EmailAddress; var recId = GetRecIdForUser(userId, db); var recTeacher = db.RecTeacher.Where(rt => rt.TeacherId == teacher.TeacherId && rt.RecId == recId).FirstOrDefault(); db.Update(recTeacher); recTeacher.IsAdministrator = teacher.IsAdministrator; if (teacher.IsDisabled) { recTeacher.DisableDate = DateTime.Now; } foreach (CClassTerm classTerm in teacher.ClassesTaught) { var dbClassTerm = db.ClassTermTeacher.Where(ctt => ctt.TeacherId == teacher.TeacherId && ctt.ClassTermId == classTerm.ClassTermId).FirstOrDefault(); if (dbClassTerm == null) { db.Add(new ClassTermTeacher { ClassTermId = classTerm.ClassTermId, TeacherId = teacher.TeacherId }); } else if (classTerm.Operation == Operation.Deleted) { db.Remove(dbClassTerm); } } db.SaveChanges(); } } catch (Exception e) { var sException = new ServerException(e.Message, e, false); LogServerException(sException); } }
public static void SignOut(string authToken) { try { using (var db = new RecContext()) { var teacher = db.Teacher.Where(t => t.AuthorizationToken == authToken).FirstOrDefault(); if (teacher == null) { return; } db.Update(teacher); teacher.AuthorizationToken = null; db.SaveChanges(); } } catch (Exception e) { var sException = new ServerException(e.Message, e, true); LogServerException(sException); } }
// POST api/RecPayment public IHttpActionResult Post(recPayment recPayment) { if (!ModelState.IsValid) { return(BadRequest()); } // Authorization Check //if (condition) //return StatusCode(HttpStatusCode.Forbidden); //if (condition) //return StatusCode(HttpStatusCode.NoContent); _context.RecPayments.Add(recPayment); // AutoMapper could be used _context.SaveChanges(); return(Ok()); }