public IActionResult Insert(MenteeInsertModel menteeInsertModel) { BaseResponseDto responseDto = null; if (menteeInsertModel == null) { return(BadRequest("Mentee info must not be null")); } try { responseDto = _mentee.Insert(menteeInsertModel); } catch (Exception e) { return(StatusCode(500, e)); } return(Ok(responseDto.Message)); }
public BaseResponseDto Insert(MenteeInsertModel menteeInsertModel) { BaseResponseDto responseDto = null; #region Check input if (menteeInsertModel == null) { responseDto = new BaseResponseDto { Status = 1, Message = "Faulthy mentee info" }; return(responseDto); } #endregion #region Insert mentee into database Guid userId = Guid.NewGuid(); Guid menteeId = Guid.NewGuid(); try { Mentee newMentee = new Mentee { MenteeId = menteeId, User = new User { UserId = userId, Email = menteeInsertModel.User.Email, Fullname = menteeInsertModel.User.Fullname, YearOfBirth = menteeInsertModel.User.YearOfBirth, AvatarUrl = menteeInsertModel.User.AvatarUrl, Balance = 0, Phone = menteeInsertModel.User.Phone, Description = "" }, UserId = userId, IsDisable = false }; _uow.GetRepository <Mentee>().Insert(newMentee); _uow.Commit(); } catch (Exception e) { throw e; } #endregion string jwtToken = tokenManager.CreateUserAccessToken(new UserAuthModel { Id = menteeId, Email = menteeInsertModel.User.Email, RoleName = "mentee" }); responseDto = new BaseResponseDto { Status = 0, Message = jwtToken }; return(responseDto); }