/// <summary> /// Modify data of Student /// </summary> /// <param name="objStudent"></param> /// <returns></returns> public DTResponse ModifyStudent(DTStudent objStudent) { DTResponse Resp = new DTResponse(); try { var student = _ObjStudentRepository.GetAllBy(i => i.Id == objStudent.Id).FirstOrDefault(); if (student != null) { student = _Objmapper.Map <Student>(objStudent); _ObjStudentRepository.Update(student); Resp.response = true; Resp.message = "Success"; } else { Resp.response = false; Resp.message = "Not found"; } } catch (Exception ex) { Resp.response = false; Resp.message = ex.Message; } return(Resp); }
/// <summary> /// Insert new students /// </summary> /// <param name="objStudent"></param> /// <returns>DTResponse</returns> public DTResponse CreateStudent(DTStudent objStudent) { DTResponse Resp = new DTResponse(); try { var StudentBD = _Objmapper.Map <Student>(objStudent); _ObjStudentRepository.Create(StudentBD); Resp.response = true; Resp.message = "Success"; } catch (Exception ex) { Resp.message = ex.Message; } return(Resp); }
public ActionResult <DTResponse> CreateStudent(DTStudent objStudent) { DTResponse Resp = new DTResponse(); DTStudentValidator objStudentValidator = new DTStudentValidator(); ValidationResult result = new ValidationResult(); //Validate fields required result = objStudentValidator.Validate(objStudent); if (result.IsValid) { Resp = _ObjStudent.CreateStudent(objStudent); } else { Resp.response = false; foreach (var failure in result.Errors) { Resp.message += "Error was: " + failure.ErrorMessage + "-> "; } } return(Resp); }