public ApiSimpleResult<FacultyModel> DeleteFaculty(FacultyModel faculty) { var result = new ApiSimpleResult<FacultyModel>(); var response = FacultySvc.DeleteFaculty(faculty); if (response != null) result = response; return result; }
public ApiSimpleResult<FacultyModel> AddFaculty(FacultyModel faculty) { var result = new ApiSimpleResult<FacultyModel>(); var response = FacultySvc.AddFaculty(faculty); if (response != null) result.Data = response; return result; }
public FacultyModel GetFacultyDetails(int id) { var response = new FacultyModel(); var faculty = DbContext.Faculties.Find(id); if (faculty != null) { response.FacultyId = faculty.FacultyId; response.FacultyName = faculty.FacultyName; response.Note = faculty.Note; response.Status = faculty.GeneralStatus.StatusName; response.GeneralStatus = faculty.GeneralStatus; } return response; }
public FacultyModel AddFaculty(FacultyModel faculty) { var result = new FacultyModel(); var status = new GeneralStatus { StatusName = faculty.Status, CreateTime = DateTime.Now, UpdateTime = DateTime.Now }; DbContext.GeneralStatuses.Add(status); var newFaculty = new Faculty { FacultyName = faculty.FacultyName, Note = faculty.Note, GeneralStatusId = status.StatusId, DirectorId = faculty.DirectorId, ProViceId = faculty.ProViceId }; DbContext.Faculties.Add(newFaculty); DbContext.SaveChanges(); result.FacultyId = newFaculty.FacultyId; return result; }
public FacultyModel SaveFaculty(FacultyModel item) { var result = new FacultyModel(); var status = DbContext.GeneralStatuses.Find(item.GeneralStatus.StatusId); status.UpdateTime = DateTime.Now; status.StatusName = item.Status; DbContext.Entry(status).State = EntityState.Modified; var faculty = DbContext.Faculties.Find(item.FacultyId); if (faculty != null) { faculty.FacultyName = item.FacultyName; faculty.Note = item.Note; faculty.DirectorId = item.DirectorId; faculty.ProViceId = item.ProViceId; DbContext.Entry(faculty).State = EntityState.Modified; } try { DbContext.SaveChanges(); result.FacultyId = item.FacultyId; result.FacultyName = item.FacultyName; } catch (DbUpdateConcurrencyException ex) { return null; } return result; }
public ApiSimpleResult<FacultyModel> DeleteFaculty(FacultyModel item) { var status = DbContext.GeneralStatuses.Find(item.GeneralStatus.StatusId); DbContext.Entry(status).State = EntityState.Deleted; var deleteItem = DbContext.Faculties.Find(item.FacultyId); DbContext.Entry(deleteItem).State = EntityState.Deleted; var result = new ApiSimpleResult<FacultyModel>(); 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; }