Example #1
0
        public HttpResponseMessage AddUser(UserSignUpViewModel userParam)
        {
            UserManager userManager = new UserManager();
            HistoryManager historyManager = new HistoryManager();
            try
            {
                var user = new User();
                user.UserName = userParam.UserName;
                user.Password = userParam.Password;
                user.Email = userParam.Email;
                user.FirstName = userParam.FirstName;
                user.MiddleName = userParam.MiddleName;
                user.LastName = userParam.LastName;

                userManager.Create(user);
                var dbUser = userManager.FindUserEmail(user.Email);
                historyManager.AddHistory(new History(dbUser)
                {
                    Activity = Activities.Joined,
                    Description = Helper.GenerateActivityDescription(dbUser, Activities.Joined)
                });
                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, user);
                return response;
            }
            catch (Exception ex)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message);
            }
        }
Example #2
0
 public HttpResponseMessage AuthenticateUser(UserSignInViewModel userParam)
 {
     UserManager userManager = new UserManager();
     HistoryManager historyManager = new HistoryManager();
     try
     {
         var user = userManager.FindAuthenticatedUser(userParam.UserName, userParam.Password);
         var dbUser = userManager.FindUserEmail(user.Email);
         historyManager.AddHistory(new History(dbUser)
         {
             Activity = Activities.Login,
             Description = Helper.GenerateActivityDescription(dbUser, Activities.Login)
         });
         HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, user);
         return response;
     }
     catch (Exception ex)
     {
         return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message);
     }
 }