public ApiSimpleResult<FacultyCourseModel> DeleteFacultyCourse(FacultyCourseModel facultyCourse) { var result = new ApiSimpleResult<FacultyCourseModel>(); var response = FacultySvc.DeleteFacultyCourse(facultyCourse); if (response != null) result = response; return result; }
public ApiSimpleResult<FacultyCourseModel> DeleteFacultyCourse(FacultyCourseModel item) { var status = DbContext.GeneralStatuses.Find(item.GeneralStatus.StatusId); DbContext.Entry(status).State = EntityState.Deleted; var deleteItem = DbContext.FacultyCourses.Find(item.FacultyCourseId); DbContext.Entry(deleteItem).State = EntityState.Deleted; var result = new ApiSimpleResult<FacultyCourseModel>(); try { DbContext.SaveChanges(); result.StatusString = "Successful"; result.Message = "Delete data successfully"; result.Data = item; } catch (DbUpdateConcurrencyException ex) { result.Message = "Error"; result.StatusString = "Error"; } return result; }
public FacultyCourseModel GetFacultyCourseDetails(int id) { var response = new FacultyCourseModel(); var item = DbContext.FacultyCourses.Find(id); if (item != null) { response.FacultyCourseId = item.FacultyCourseId; response.FacultyId = item.FacultyId; response.FacultyName = item.Faculty.FacultyName; response.CourseCode = item.Course.CourseCode; response.CourseId = item.CourseId; response.Note = item.Note; response.Status = item.GeneralStatus.StatusName; response.GeneralStatus = item.GeneralStatus; } return response; }
public FacultyCourseModel SaveFacultyCourse(FacultyCourseModel item) { var result = new FacultyCourseModel(); var status = DbContext.GeneralStatuses.Find(item.GeneralStatus.StatusId); status.UpdateTime = DateTime.Now; status.StatusName = item.Status; DbContext.Entry(status).State = EntityState.Modified; var editItem = DbContext.FacultyCourses.Find(item.FacultyCourseId); if (editItem != null) { editItem.FacultyId = item.FacultyId; editItem.CourseId = item.CourseId; editItem.Note = item.Note; DbContext.Entry(editItem).State = EntityState.Modified; } try { DbContext.SaveChanges(); result.FacultyCourseId = item.FacultyCourseId; } catch (DbUpdateConcurrencyException ex) { return null; } return result; }
public FacultyCourseModel AddFacultyCourse(FacultyCourseModel facultyCourse) { var result = new FacultyCourseModel(); var status = new GeneralStatus { StatusName = facultyCourse.Status, CreateTime = DateTime.Now, UpdateTime = DateTime.Now }; DbContext.GeneralStatuses.Add(status); var newItem = new FacultyCourse { FacultyId = facultyCourse.FacultyId, CourseId = facultyCourse.CourseId, Note = facultyCourse.Note, GeneralStatusId = status.StatusId }; DbContext.FacultyCourses.Add(newItem); DbContext.SaveChanges(); result.FacultyCourseId = newItem.FacultyCourseId; return result; }