Ejemplo n.º 1
0
        public IHttpActionResult SaveUserDetail(UserDetail userDetail)
        {
            try
            {
                if (HttpContext.Current.User.Identity.IsAuthenticated)
                {
                    if (userDetail.Id == 0)
                    {
                        if (_userDetailContext.CheckUserNameExist(userDetail.UserName))
                        {
                            return(Ok(new { IsUserNameExist = true }));
                        }
                        else if (_userDetailContext.CheckUserEmailExist(userDetail.Email))
                        {
                            return(Ok(new { IsUserEmailExist = true }));
                        }
                        else if (_userDetailContext.CheckEmployeeIdExist(userDetail.EmployeeId, userDetail.Id))
                        {
                            return(Ok(new { IsEmployeeIdExist = true }));
                        }
                        else if (_userDetailContext.CheckMobileNoExist(userDetail.MobileNumber, userDetail.Id))
                        {
                            return(Ok(new { IsMobileNoExist = true }));
                        }

                        Register(userDetail);
                        UserDetail userInfo = _userDetailContext.AddUserDetail(userDetail, HttpContext.Current.User.Identity.Name);
                        SendEmail(userDetail);
                        return(Ok(userInfo));
                    }
                    else
                    {
                        if (_userDetailContext.CheckEmployeeIdExist(userDetail.EmployeeId, userDetail.Id))
                        {
                            return(Ok(new { IsEmployeeIdExist = true }));
                        }
                        else if (_userDetailContext.CheckMobileNoExist(userDetail.MobileNumber, userDetail.Id))
                        {
                            return(Ok(new { IsMobileNoExist = true }));
                        }
                        var userRole = _roleRepository.GetRoleById(userDetail.RoleId);
                        userDetail.RoleName = userRole.RoleName;
                        var status = _userDetailContext.UpdateUserDetail(userDetail);
                        return(Ok(new { userDetail = userDetail, status = status }));
                    }
                }
                else
                {
                    return(BadRequest());
                }
            }
            catch (Exception ex)
            {
                _errorLog.LogException(ex);
                throw;
            }
        }