Пример #1
0
 public Entity.BaseResponse <Entity.UserResponse> Manage([FromBody] Entity.AddAdminUserRequest request)
 {
     Entity.BaseResponse <Entity.UserResponse> response = new Entity.BaseResponse <Entity.UserResponse>(true);
     try
     {
         var status = _adminUserService.Manage(request);
         response.IsSuccess = status.Success;
         response.Message   = status.Message;
         response.Data      = status.Data;
     }
     catch (Exception ex)
     {
         base.LogException(ex);
         response.IsSuccess = false;
         response.Message   = ex.Message.ToString();
         return(new Entity.BaseResponse <Entity.UserResponse>(false, ex.Message));
     }
     return(response);
 }
Пример #2
0
        public Entity.ActionStatus Manage(Entity.AddAdminUserRequest request)
        {
            Entity.ActionStatus actionStatus = new ActionStatus(true);
            try
            {
                if (request.Id == null || request.Id == Guid.Empty)
                {
                    var checkExisting = _adminUserRepository.FindBy(x => x.Email.Equals(request.Email) && x.IsActive && !x.IsDeleted).FirstOrDefault();

                    if (checkExisting == null)
                    {
                        var adminUser = Mapper.Configuration.Mapper.Map <Entity.AddAdminUserRequest, Model.AdminUser>(request);



                        adminUser.CreatedBy   = component.helper.SolutionConfiguration.CurrentUserId;
                        adminUser.CreatedDate = DateTime.Now;
                        adminUser.IsActive    = true;
                        adminUser.IsDeleted   = false;
                        adminUser.Guid        = Guid.NewGuid();
                        adminUser.CompanyGuid = component.helper.SolutionConfiguration.CompanyId;

                        actionStatus = _adminUserRepository.Insert(adminUser);

                        actionStatus.Data = Mapper.Configuration.Mapper.Map <Model.AdminUser, Entity.UserResponse>(actionStatus.Data);

                        if (!actionStatus.Success)
                        {
                            _logger.Error($"Admin User is not added in solution database, Error: {actionStatus.Message}");
                            actionStatus.Success = false;
                            actionStatus.Message = "Something Went Wrong!";
                        }
                    }
                    else
                    {
                        // _logger.Error($"AdminUser is not updated in solution database, Error: {actionStatus.Message}");
                        actionStatus.Success = false;
                        actionStatus.Message = "Email Id Already Registered.";
                    }
                }
                else
                {
                    var oldAdminUser = _adminUserRepository.FindBy(x => x.Guid.Equals(request.Id)).FirstOrDefault();
                    if (oldAdminUser == null)
                    {
                        throw new NotFoundCustomException($"{CommonException.Name.NoRecordsFound} : AdminUser");
                    }
                    else
                    {
                        var checkExisting = _adminUserRepository.FindBy(x => x.Email.Equals(request.Email) && x.IsActive && !x.IsDeleted && x.Guid != oldAdminUser.Guid).FirstOrDefault();
                        if (checkExisting == null)
                        {
                            var existingPassword = oldAdminUser.Password;
                            var dbAdminUser      = Mapper.Configuration.Mapper.Map(request, oldAdminUser);

                            dbAdminUser.CreatedBy   = oldAdminUser.CreatedBy;
                            dbAdminUser.CreatedDate = oldAdminUser.CreatedDate;
                            dbAdminUser.UpdatedDate = DateTime.Now;
                            dbAdminUser.UpdatedBy   = component.helper.SolutionConfiguration.CurrentUserId;
                            dbAdminUser.CompanyGuid = component.helper.SolutionConfiguration.CompanyId;
                            if (string.IsNullOrEmpty(dbAdminUser.Password))
                            {
                                dbAdminUser.Password = existingPassword;
                            }
                            actionStatus = _adminUserRepository.Update(dbAdminUser);

                            actionStatus.Data = Mapper.Configuration.Mapper.Map <Model.AdminUser, Entity.UserResponse>(actionStatus.Data);

                            if (!actionStatus.Success)
                            {
                                _logger.Error($"AdminUser is not updated in solution database, Error: {actionStatus.Message}");
                                actionStatus.Success = false;
                                actionStatus.Message = "Something Went Wrong!";
                            }
                        }
                        else
                        {
                            actionStatus.Success = false;
                            actionStatus.Message = "Email Id Already Registered With Another User.";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error(Constants.ACTION_EXCEPTION, "AdminUserManager.Manage " + ex);
                actionStatus.Success = false;
                actionStatus.Message = ex.Message;
            }

            return(actionStatus);
        }
        public Entity.ActionStatus Manage(Entity.AddAdminUserRequest request)
        {
            Entity.ActionStatus actionStatus = new ActionStatus(true);
            try
            {
                if (request.Id == null || request.Id == Guid.Empty)
                {
                    var checkExisting = _adminUserRepository.FindBy(x => x.Email.Equals(request.Email) && x.IsActive && !x.IsDeleted).FirstOrDefault();

                    if (checkExisting == null)
                    {
                        var adminUser = Mapper.Configuration.Mapper.Map <Entity.AddAdminUserRequest, Model.AdminUser>(request);



                        adminUser.CreatedBy   = SolutionConfiguration.CurrentUserId;
                        adminUser.CreatedDate = DateTime.Now;
                        adminUser.IsActive    = true;
                        adminUser.IsDeleted   = false;
                        adminUser.Guid        = Guid.NewGuid();
                        adminUser.CompanyGuid = SolutionConfiguration.CompanyId;

                        actionStatus = _adminUserRepository.Insert(adminUser);

                        actionStatus.Data = Mapper.Configuration.Mapper.Map <Model.AdminUser, Entity.UserResponse>(actionStatus.Data);

                        if (!actionStatus.Success)
                        {
                            _logger.ErrorLog(new Exception($"Admin User is not added in solution database, Error: {actionStatus.Message}"), this.GetType().Name, MethodBase.GetCurrentMethod().Name);
                            actionStatus.Success = false;
                            actionStatus.Message = "Something Went Wrong!";
                        }
                    }
                    else
                    {
                        // _logger.Error($"AdminUser is not updated in solution database, Error: {actionStatus.Message}");
                        actionStatus.Success = false;
                        actionStatus.Message = "Email Id Already Registered.";
                    }
                }
                else
                {
                    var oldAdminUser = _adminUserRepository.FindBy(x => x.Guid.Equals(request.Id)).FirstOrDefault();
                    if (oldAdminUser == null)
                    {
                        throw new NotFoundCustomException($"{CommonException.Name.NoRecordsFound} : AdminUser");
                    }
                    else
                    {
                        var dbAdminUser = Mapper.Configuration.Mapper.Map(request, oldAdminUser);

                        dbAdminUser.CreatedBy   = oldAdminUser.CreatedBy;
                        dbAdminUser.CreatedDate = oldAdminUser.CreatedDate;
                        dbAdminUser.UpdatedDate = DateTime.Now;
                        dbAdminUser.UpdatedBy   = SolutionConfiguration.CurrentUserId;
                        dbAdminUser.CompanyGuid = SolutionConfiguration.CompanyId;

                        actionStatus = _adminUserRepository.Update(dbAdminUser);

                        actionStatus.Data = Mapper.Configuration.Mapper.Map <Model.AdminUser, Entity.UserResponse>(actionStatus.Data);

                        if (!actionStatus.Success)
                        {
                            _logger.ErrorLog(new Exception($"AdminUser is not updated in solution database, Error: {actionStatus.Message}"), this.GetType().Name, MethodBase.GetCurrentMethod().Name);
                            actionStatus.Success = false;
                            actionStatus.Message = "Something Went Wrong!";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.ErrorLog(ex, this.GetType().Name, MethodBase.GetCurrentMethod().Name);
                actionStatus.Success = false;
                actionStatus.Message = ex.Message;
            }

            return(actionStatus);
        }