public int AddDetail(BasicDetails data) { if (db != null) { db.BasicDetails.Add(data); db.SaveChanges(); MarksDetails marks = new MarksDetails() { Id = data.Id, CurrentYear = null, Sem1 = null, Sem2 = null, Sem3 = null, Sem4 = null, Sem5 = null, Sem6 = null, Sem7 = null, Sem8 = null, TotalMaxMarks = null, TotalObtainedMarks = null, Percentage = null }; LoginCredentials newuser = new LoginCredentials() { UserName = data.Email, Password = data.Phone, Role = "Student" }; db.MarksDetails.Add(marks); db.LoginCredentials.Add(newuser); db.SaveChanges(); return(data.Id); } return(0); }
public IHttpActionResult PutStudent(int id, Student student) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != student.Id) { return(BadRequest()); } db.Entry(student).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!StudentExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public HttpResponseMessage Edit([FromBody] Student s) { using (var context = new StudentManagementContext()) { try { if (s != null) { Student stu = new Student(); stu = context.Students.Find(s.Id); stu.RollNumber = s.RollNumber; stu.Fullname = s.Fullname; stu.Attendance = s.Attendance; stu.DivisionId = s.DivisionId; stu.Standard = s.Standard; stu.Gpa = s.Gpa; stu.DateOfBirth = s.DateOfBirth; stu.IsActive = s.IsActive; context.SaveChanges(); return(new HttpResponseMessage(HttpStatusCode.OK)); } else { return(new HttpResponseMessage(HttpStatusCode.Unauthorized)); } } catch { return(new HttpResponseMessage(HttpStatusCode.Unauthorized)); } } }
public HttpResponseMessage Post([FromBody] Division d) { try { Division div = new Division(); div.Name = d.Name; if (d != null) { using (var context = new StudentManagementContext()) { context.Divisions.Add(div); context.SaveChanges(); return(new HttpResponseMessage(HttpStatusCode.OK)); } } else { return(new HttpResponseMessage(HttpStatusCode.Unauthorized)); } } catch (Exception e) { return(new HttpResponseMessage(HttpStatusCode.Unauthorized)); } }
public int UpdateDetail([FromBody] BasicDetails model) { if (db != null) { db.BasicDetails.Update(model); db.SaveChanges(); return(1); } return(0); }
public int UpdateMarks([FromBody] MarksDetails model) { if (db != null) { db.MarksDetails.Update(model); db.SaveChanges(); return(1); } return(0); }
public HttpResponseMessage Delete([FromBody] int id) { using (var context = new StudentManagementContext()) { Student stu = new Student(); stu = context.Students.Find(id); if (stu == null) { return(new HttpResponseMessage(HttpStatusCode.Unauthorized)); } context.Students.Remove(stu); context.SaveChanges(); return(new HttpResponseMessage(HttpStatusCode.OK)); } }
public void Save() { _studentManagementContext.SaveChanges(); }