Esempio n. 1
0
        public UserViewModel()
        {
            Users = new UserModel();

            UsersUi = new UserUiModel();

            Submit = new AsyncCommand(DisplayAlertBox);
        }
Esempio n. 2
0
        public UserViewModel()
        {
            Users = new UserModel();

            UsersUi = new UserUiModel();

            BindUserData();

            Submit = new AsyncCommand(OnSubmit);
        }
Esempio n. 3
0
        public async Task <IActionResult> PostStoreRouteAsync(
            [FromBody] StoreForCreationUiModel storeForCreationUiModel)
        {
            var userAudit = await _inquiryUserProcessor.GetUserByLoginAsync(GetEmailFromClaims());

            if (userAudit == null)
            {
                userAudit = new UserUiModel()
                {
                    Id = Guid.NewGuid()
                };
                //return BadRequest("AUDIT_USER_NOT_EXIST");
            }

            var newCreatedStore =
                await _createStoreProcessor.CreateStoreAsync(userAudit.Id, storeForCreationUiModel);

            switch (newCreatedStore.Message)
            {
            case ("SUCCESS_CREATION"):
            {
                Log.Information(
                    $"--Method:PostStoreRouteAsync -- Message:STORE_CREATION_SUCCESSFULLY -- " +
                    $"Datetime:{DateTime.Now} -- StoreInfo:{storeForCreationUiModel.StoreName}");
                return(Created(nameof(PostStoreRouteAsync), newCreatedStore));
            }

            case ("ERROR_ALREADY_EXISTS"):
            {
                Log.Error(
                    $"--Method:PostStoreRouteAsync -- Message:ERROR_STORE_ALREADY_EXISTS -- " +
                    $"Datetime:{DateTime.Now} -- StoreInfo:{storeForCreationUiModel.StoreName}");
                return(BadRequest(new { errorMessage = "STORE_ALREADY_EXISTS" }));
            }

            case ("ERROR_STORE_NOT_MADE_PERSISTENT"):
            {
                Log.Error(
                    $"--Method:PostStoreRouteAsync -- Message:ERROR_STORE_NOT_MADE_PERSISTENT -- " +
                    $"Datetime:{DateTime.Now} -- StoreInfo:{storeForCreationUiModel.StoreName}");
                return(BadRequest(new { errorMessage = "ERROR_CREATION_NEW_STORE" }));
            }

            case ("UNKNOWN_ERROR"):
            {
                Log.Error(
                    $"--Method:PostStoreRouteAsync -- Message:ERROR_CREATION_NEW_STORE -- " +
                    $"Datetime:{DateTime.Now} -- StoreInfo:{storeForCreationUiModel.StoreName}");
                return(BadRequest(new { errorMessage = "ERROR_CREATION_NEW_STORE" }));
            }
            }

            return(NotFound());
        }
        public UserViewModel(IUserService userService)
        {
            this.userService = userService;

            UserM   = new UserModel();
            UserUiM = new UserUiModel();

            UserUiM.IsCancelEnabled = true;
            UserUiM.IsSubmitEnabled = false;

            DisplayCommand = new Command(() => this.OnDisplay());
            CancelCommand  = new Command <ContentPage>((contentPage) => this.OnCancel(contentPage));
        }
        public UserViewModel()
        {
            // Get User Service
            this.userService = DependencyService.Get <IUserService>();

            UserM   = new UserModel();
            UserUiM = new UserUiModel();

            UserUiM.IsCancelEnabled = true;
            UserUiM.IsSubmitEnabled = false;

            DisplayCommand = new Command(() => this.OnDisplay());
            CancelCommand  = new Command <ContentPage>((contentPage) => this.OnCancel(contentPage));
        }
Esempio n. 6
0
        public Task <UserUiModel> CreateUserAsync(Guid accountIdToCreateThisUser,
                                                  UserForRegistrationUiModel newUserForRegistration)
        {
            var response =
                new UserUiModel()
            {
                Message = "START_CREATION"
            };

            if (newUserForRegistration == null)
            {
                response.Message = "ERROR_INVALID_USER_MODEL";
                return(Task.Run(() => response));
            }

            try
            {
                var userToBeCreated = new User();
                userToBeCreated.InjectWithInitialAttributes(newUserForRegistration);
                userToBeCreated.InjectWithAuditCreation(accountIdToCreateThisUser);

                var roleToBeInjected = _roleRepository.FindBy(newUserForRegistration.UserRoleId);

                if (roleToBeInjected == null)
                {
                    throw new RoleDoesNotExistException(newUserForRegistration.UserRoleId);
                }

                var userRoleToBeInjected = new UserRole();

                userRoleToBeInjected.InjectWithRole(roleToBeInjected);
                userRoleToBeInjected.InjectWithAuditCreation(accountIdToCreateThisUser);
                var customerToBeInjected = new Customer()
                {
                    Firstname = newUserForRegistration.Firstname,
                    Lastname  = newUserForRegistration.Lastname,
                    Phone     = newUserForRegistration.Phone,
                    Notes     = newUserForRegistration.Notes,
                    Address   = new Address()
                    {
                        StreetOne = newUserForRegistration.AddressStreetOne,
                        StreetTwo = newUserForRegistration.AddressStreetTwo,
                        PostCode  = newUserForRegistration.AddressPostCode,
                        City      = newUserForRegistration.AddressCity,
                        Region    = newUserForRegistration.AddressRegion,
                    },
                    Email = newUserForRegistration.Login,
                };

                customerToBeInjected.InjectWithAuditCreation(accountIdToCreateThisUser);

                userToBeCreated.InjectWithCustomer(customerToBeInjected);
                userToBeCreated.InjectWithUserRole(userRoleToBeInjected);

                ThrowExcIfUserCannotBeCreated(userToBeCreated);
                ThrowExcIfThisUserAlreadyExist(userToBeCreated);

                Log.Debug(
                    $"Create User: {newUserForRegistration.Login}" +
                    "--CreateUser--  @NotComplete@ [CreateUserProcessor]. " +
                    "Message: Just Before MakeItPersistence");

                MakeUserPersistent(userToBeCreated);

                Log.Debug(
                    $"Create User: {newUserForRegistration.Login}" +
                    "--CreateUser--  @NotComplete@ [CreateUserProcessor]. " +
                    "Message: Just After MakeItPersistence");
                response         = ThrowExcIfUserWasNotBeMadePersistent(userToBeCreated);
                response.Message = "SUCCESS_CREATION";
            }
            catch (RoleDoesNotExistException r)
            {
                response.Message = "ERROR_INVALID_ROLE_NAME";
                Log.Error(
                    $"Create User: {newUserForRegistration.Login}" +
                    $"Error Message:{response.Message}" +
                    "--CreateUser--  @NotComplete@ [CreateUserProcessor]");
            }
            catch (InvalidUserException e)
            {
                response.Message = "ERROR_INVALID_USER_MODEL";
                Log.Error(
                    $"Create User: {newUserForRegistration.Login}" +
                    $"Error Message:{response.Message}" +
                    "--CreateUser--  @NotComplete@ [CreateUserProcessor]. " +
                    $"Broken rules: {e.BrokenRules}");
            }
            catch (UserEmailOrLoginAlreadyExistsException ex)
            {
                response.Message = "ERROR_USER_ALREADY_EXISTS";
                Log.Error(
                    $"Create User: {newUserForRegistration.Login}" +
                    $"Error Message:{response.Message}" +
                    "--CreateUser--  @fail@ [CreateUserProcessor]. " +
                    $"@inner-fault:{ex?.Message} and {ex?.InnerException}");
            }
            catch (UserDoesNotExistAfterMadePersistentException exx)
            {
                response.Message = "ERROR_USER_NOT_MADE_PERSISTENT";
                Log.Error(
                    $"Create User: {newUserForRegistration.Login}" +
                    $"Error Message:{response.Message}" +
                    "--CreateUser--  @fail@ [CreateUserProcessor]." +
                    $" @inner-fault:{exx?.Message} and {exx?.InnerException}");
            }
            catch (Exception exxx)
            {
                response.Message = "UNKNOWN_ERROR";
                Log.Error(
                    $"Create User: {newUserForRegistration.Login}" +
                    $"Error Message:{response.Message}" +
                    $"--CreateUser--  @fail@ [CreateUserProcessor]. " +
                    $"@inner-fault:{exxx.Message} and {exxx.InnerException}");
            }

            return(Task.Run(() => response));
        }
Esempio n. 7
0
        public Task <UserUiModel> CreateUserAsync(UserForRegistrationUiModel newUserForRegistration)
        {
            var response =
                new UserUiModel()
            {
                Message = "START_CREATION"
            };

            if (newUserForRegistration == null)
            {
                response.Message = "ERROR_INVALID_USER_MODEL";
                return(Task.Run(() => response));
            }

            try
            {
                var userToBeCreated = new User();
                userToBeCreated.InjectWithInitialAttributes(newUserForRegistration.Displayname,
                                                            newUserForRegistration.Username, newUserForRegistration.Email, newUserForRegistration.Password, newUserForRegistration.Address);

                ThrowExcIfUserCannotBeCreated(userToBeCreated);
                ThrowExcIfThisUserAlreadyExist(userToBeCreated);

                Log.Debug(
                    $"Create User: {newUserForRegistration.Username}" +
                    "--CreateUser--  @NotComplete@ [CreateUserProcessor]. " +
                    "Message: Just Before MakeItPersistence");

                MakeUserPersistent(userToBeCreated);

                Log.Debug(
                    $"Create User: {newUserForRegistration.Username}" +
                    "--CreateUser--  @NotComplete@ [CreateUserProcessor]. " +
                    "Message: Just After MakeItPersistence");

                response         = ThrowExcIfUserWasNotBeMadePersistent(userToBeCreated);
                response.Message = "SUCCESS_CREATION";
            }
            catch (InvalidUserException e)
            {
                response.Message = "ERROR_INVALID_USER_MODEL";
                Log.Error(
                    $"Create User: {newUserForRegistration.Username}" +
                    $"Error Message:{response.Message}" +
                    "--CreateUser--  @NotComplete@ [CreateUserProcessor]. " +
                    $"Broken rules: {e.BrokenRules}");
            }
            catch (UserEmailOrLoginAlreadyExistsException ex)
            {
                response.Message = "ERROR_USER_ALREADY_EXISTS";
                Log.Error(
                    $"Create User: {newUserForRegistration.Username}" +
                    $"Error Message:{response.Message}" +
                    "--CreateUser--  @fail@ [CreateUserProcessor]. " +
                    $"@inner-fault:{ex?.Message} and {ex?.InnerException}");
            }
            catch (UserDoesNotExistAfterMadePersistentException exx)
            {
                response.Message = "ERROR_USER_NOT_MADE_PERSISTENT";
                Log.Error(
                    $"Create User: {newUserForRegistration.Username}" +
                    $"Error Message:{response.Message}" +
                    "--CreateUser--  @fail@ [CreateUserProcessor]." +
                    $" @inner-fault:{exx?.Message} and {exx?.InnerException}");
            }
            catch (Exception exxx)
            {
                response.Message = "UNKNOWN_ERROR";
                Log.Error(
                    $"Create User: {newUserForRegistration.Username}" +
                    $"Error Message:{response.Message}" +
                    $"--CreateUser--  @fail@ [CreateUserProcessor]. " +
                    $"@inner-fault:{exxx.Message} and {exxx.InnerException}");
            }

            return(Task.Run(() => response));
        }