コード例 #1
0
 public ApiSimpleResult<StudentModel> DeleteStudent(StudentModel queryModel)
 {
     var result = new ApiSimpleResult<StudentModel>();
     var response = FacultySvc.DeleteStudent(queryModel);
     if (response != null)
         result = response;
     return result;
 }
コード例 #2
0
 public ApiSimpleResult<StudentModel> DeleteStudent(StudentModel queryModel)
 {
     var status = DbContext.GeneralStatuses.Find(queryModel.GeneralStatus.StatusId);
     DbContext.Entry(status).State = EntityState.Deleted;
     var deleteItem = DbContext.Students.Find(queryModel.StudentId);
     DbContext.Entry(deleteItem).State = EntityState.Deleted;
     var result = new ApiSimpleResult<StudentModel>();
     try
     {
         DbContext.SaveChanges();
         result.StatusString = "Successful";
         result.Message = "Delete data successfully";
         result.Data = queryModel;
     }
     catch (DbUpdateConcurrencyException ex)
     {
         result.Message = "Error";
         result.StatusString = "Error";
     }
     return result;
 }
コード例 #3
0
        public StudentModel GetStudentDetails(int id)
        {
            var response = new StudentModel();
            var detailItem = DbContext.Students.Find(id);
            if (detailItem != null)
            {
                response.StudentId = detailItem.StudentId;
                response.StudentCode = detailItem.StudentCode;
                response.FullName = detailItem.FullName;
                response.Address = detailItem.Address;
                response.PhoneNumber = detailItem.PhoneNumber;
                response.DateOfBirth = detailItem.DateOfBirth;
                response.Email = detailItem.Email;
                response.GeneralStatus = detailItem.GeneralStatus;
                response.Status = detailItem.GeneralStatus.StatusName;
            }

            return response;
        }
コード例 #4
0
 public StudentModel SaveStudent(StudentModel queryModel)
 {
     var result = new StudentModel();
     var status = DbContext.GeneralStatuses.Find(queryModel.GeneralStatus.StatusId);
     status.UpdateTime = DateTime.Now;
     status.StatusName = queryModel.Status;
     DbContext.Entry(status).State = EntityState.Modified;
     var editItem = DbContext.Students.Find(queryModel.StudentId);
     if (editItem != null)
     {
         editItem.StudentCode = queryModel.StudentCode;
         editItem.FullName = queryModel.FullName;
         editItem.Address = queryModel.Address;
         editItem.PhoneNumber = queryModel.PhoneNumber;
         editItem.DateOfBirth = queryModel.DateOfBirth;
         editItem.Email = queryModel.Email;
         DbContext.Entry(editItem).State = EntityState.Modified;
     }
     try
     {
         DbContext.SaveChanges();
         result.StudentId = queryModel.StudentId;
         result.StudentCode = queryModel.StudentCode;
     }
     catch (DbUpdateConcurrencyException ex)
     {
         return null;
     }
     return result;
 }
コード例 #5
0
 public StudentModel AddStudent(StudentModel queryModel)
 {
     var result = new StudentModel();
     var status = new GeneralStatus
     {
         StatusName = queryModel.Status,
         CreateTime = DateTime.Now,
         UpdateTime = DateTime.Now
     };
     DbContext.GeneralStatuses.Add(status);
     var newItem = new Student
     {
         StudentCode = queryModel.StudentCode,
         FullName = queryModel.FullName,
         Address = queryModel.Address,
         PhoneNumber = queryModel.PhoneNumber,
         DateOfBirth = queryModel.DateOfBirth,
         Email = queryModel.Email,
         GeneralStatusId = status.StatusId
     };
     DbContext.Students.Add(newItem);
     DbContext.SaveChanges();
     result.StudentId = newItem.StudentId;
     return result;
 }