private void AddUser(UserAccountApiModel newUser, ApiResponse <bool> response)
        {
            string enPassword = Utility.EncryptData(newUser.Password);

            using (DbContextTransaction dbTran = _context.Database.BeginTransaction())
            {
                try
                {
                    User user = newUser.ToUser();
                    user.IsActive    = true;
                    user.CreatedDate = DateTime.Now;
                    _context.Users.Add(user);
                    _context.SaveChanges();

                    UserLogin userLogin = new UserLogin
                    {
                        UserId   = user.Id,
                        UserName = newUser.UserName,
                        Password = enPassword,
                        IsActive = true
                    };
                    _context.UserLogins.Add(userLogin);
                    _context.SaveChanges();
                    dbTran.Commit();
                    response.DisplayMessage = "User has successfully registered. !!";
                }
                catch (DbEntityValidationException ex)
                {
                    dbTran.Rollback();
                    response.DisplayMessage = "failed , Please try again !!";
                    throw;
                }
            }
        }
Example #2
0
 public static User ToUser(this UserAccountApiModel userAccountApiModel)
 {
     return(new User
     {
         Id = userAccountApiModel.Id,
         FirstName = userAccountApiModel.FirstName,
         LastName = userAccountApiModel.LastName,
         Email = userAccountApiModel.Email,
         ContactNumber = userAccountApiModel.ContactNumber,
         ProfileImagePath = userAccountApiModel.ProfileImagePath,
         CreatedDate = userAccountApiModel.CreatedDate,
         IsActive = userAccountApiModel.IsActive,
     });
 }
        public ApiResponse <bool> CreateUserAccount(UserAccountApiModel newUser)
        {
            var response    = new ApiResponse <bool>();
            var isUserExist = CheckUserNameExistOrNot(newUser.UserName);

            if (isUserExist)
            {
                response.DisplayMessage = "Failed : User Name is already exist !!";
                response.Result         = false;
            }
            else
            {
                AddUser(newUser, response);
            }
            return(response);
        }
        public ApiResponse <UserAccountApiModel> UpdateUserProfile(UserAccountApiModel userProfile)
        {
            var response = new ApiResponse <UserAccountApiModel>();

            var user = _context.Users.FirstOrDefault(x => x.Id == userProfile.Id);

            if (user != null)
            {
                user.Email            = userProfile.Email;
                user.ContactNumber    = userProfile.ContactNumber;
                user.ProfileImagePath = userProfile.ProfileImagePath;

                _context.Entry(user).State = EntityState.Modified;
                int rowAffected = _context.SaveChanges();
                response.IsSucceeded = rowAffected > 0;
            }

            response.DisplayMessage = response.IsSucceeded? "Your profile has successfully updated":"Failed , Please try after some time";
            response.Result         = userProfile;

            return(response);
        }
Example #5
0
        public IHttpActionResult UpdateUserProfile()
        {
            var response = new ApiResponse <UserAccountApiModel>();

            var httpRequest = HttpContext.Current.Request;

            if (httpRequest.Params["Profile"] != null)
            {
                UserAccountApiModel user = JsonConvert.DeserializeObject <UserAccountApiModel>(httpRequest.Params["Profile"]);

                if (user != null && httpRequest.Files.Count > 0)
                {
                    string ImagePath    = string.Empty;
                    string userFileName = $"{user.Id}-{user.Email?.Split('@')[0]}";
                    ImagePath             = SaveImageFile(httpRequest, userFileName);
                    user.ProfileImagePath = ImagePath;
                }
                response = _UserAccountQueryService.UpdateUserProfile(user);
            }

            return(Ok(response));
        }
Example #6
0
        public IHttpActionResult UserRegistration([FromBody] UserAccountApiModel newUser)
        {
            var apiResponse = _UserAccountQueryService.CreateUserAccount(newUser);

            return(Ok(apiResponse));
        }