public static int InsertUser(NewUserReq newUser) { try { var user = new User() { IsActive = true, Name = newUser.Name, Tel = newUser.Tel }; using (var dbCtx = new MSDbContext()) { dbCtx.Users.Add(user); int result = dbCtx.SaveChanges(); if (result == 1) { return(user.Id); } else { throw new Exception(); } } } catch (Exception e) { var ex = new InsertIntoDataBaseException(ExceptionMessage.InsertIntoUsersException, e); Logger.Log.Error(ex.Message, ex); throw ex; } }
private Result <DMLResultResp> IsNewUserValid(NewUserReq newUser) { Result <DMLResultResp> result; if (!HasName(newUser)) { result = new Result <DMLResultResp>(null, new Error(ErrorMessage.NewAccountNameIsEmpty), false); } else if (!HasTel(newUser)) { result = new Result <DMLResultResp>(null, new Error(ErrorMessage.NewAccountTelIsEmpty), false); } else { result = new Result <DMLResultResp>(null, null, true); } return(result); }
public HttpResponseMessage Post(NewUserReq newUser) { if (ModelState.IsValid) { var result = BL.Business.Account.AddNewAccount.AddNewUser(newUser); if (!result.IsOk) { Response = Request.CreateResponse(HttpStatusCode.InternalServerError, result.Error.ErrorMessage); } else { Response = Request.CreateResponse(HttpStatusCode.OK, result); } } else { Response = Request.CreateResponse(HttpStatusCode.BadRequest); } return(Response); }
private AddNewAccount(NewUserReq newUser) { _newUser = newUser; }
public static Result <NewUserResp> AddNewUser(NewUserReq newUser) { var addNewAccount = new AddNewAccount(newUser); return(addNewAccount.AddNewUserOperation()); }
private bool HasName(NewUserReq newUser) { return(!string.IsNullOrEmpty(newUser.Name)); }
private bool HasTel(NewUserReq newUser) { return(!string.IsNullOrEmpty(newUser.Tel)); }