예제 #1
0
 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;
     }
 }
예제 #2
0
        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);
        }
예제 #3
0
 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);
 }
예제 #4
0
 private AddNewAccount(NewUserReq newUser)
 {
     _newUser = newUser;
 }
예제 #5
0
        public static Result <NewUserResp> AddNewUser(NewUserReq newUser)
        {
            var addNewAccount = new AddNewAccount(newUser);

            return(addNewAccount.AddNewUserOperation());
        }
예제 #6
0
 private bool HasName(NewUserReq newUser)
 {
     return(!string.IsNullOrEmpty(newUser.Name));
 }
예제 #7
0
 private bool HasTel(NewUserReq newUser)
 {
     return(!string.IsNullOrEmpty(newUser.Tel));
 }