コード例 #1
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());
        }
コード例 #2
0
        public async Task <IActionResult> PostCategoryRouteAsync(
            [FromBody] CategoryForCreationUiModel categoryForCreationUiModel)
        {
            var userAudit = await _inquiryUserProcessor.GetUserByLoginAsync(GetEmailFromClaims());

            if (userAudit == null)
            {
                return(BadRequest("AUDIT_USER_NOT_EXIST"));
            }

            var newCreatedCategory =
                await _createCategoryProcessor.CreateCategoryAsync(userAudit.Id, categoryForCreationUiModel);

            switch (newCreatedCategory.Message)
            {
            case ("SUCCESS_CREATION"):
            {
                Log.Information(
                    $"--Method:PostCategoryRouteAsync -- Message:CATEGORY_CREATION_SUCCESSFULLY -- " +
                    $"Datetime:{DateTime.Now} -- CategoryInfo:{categoryForCreationUiModel.CategoryName}");
                return(Created(nameof(PostCategoryRouteAsync), newCreatedCategory));
            }

            case ("ERROR_ALREADY_EXISTS"):
            {
                Log.Error(
                    $"--Method:PostCategoryRouteAsync -- Message:ERROR_CATEGORY_ALREADY_EXISTS -- " +
                    $"Datetime:{DateTime.Now} -- CategoryInfo:{categoryForCreationUiModel.CategoryName}");
                return(BadRequest(new { errorMessage = "CATEGORY_ALREADY_EXISTS" }));
            }

            case ("ERROR_CATEGORY_NOT_MADE_PERSISTENT"):
            {
                Log.Error(
                    $"--Method:PostCategoryRouteAsync -- Message:ERROR_CATEGORY_NOT_MADE_PERSISTENT -- " +
                    $"Datetime:{DateTime.Now} -- CategoryInfo:{categoryForCreationUiModel.CategoryName}");
                return(BadRequest(new { errorMessage = "ERROR_CREATION_NEW_CATEGORY" }));
            }

            case ("UNKNOWN_ERROR"):
            {
                Log.Error(
                    $"--Method:PostCategoryRouteAsync -- Message:ERROR_CREATION_NEW_CATEGORY -- " +
                    $"Datetime:{DateTime.Now} -- CategoryInfo:{categoryForCreationUiModel.CategoryName}");
                return(BadRequest(new { errorMessage = "ERROR_CREATION_NEW_CATEGORY" }));
            }
            }

            return(NotFound());
        }
コード例 #3
0
        public async Task <IActionResult> PostAdvertiserAsync([FromBody] CustomerForCreationUiModel customerForCreationUiModel)
        {
            var userAudit = await _inquiryUserProcessor.GetUserByLoginAsync(GetEmailFromClaims());

            if (userAudit == null)
            {
                return(BadRequest("AUDIT_USER_NOT_EXIST"));
            }

            if (await _inquiryCustomerProcessor.SearchIfAnyPersonByEmailOrLoginExistsAsync(customerForCreationUiModel.CustomerUserLogin))
            {
                Log.Error(
                    $"--Method:PostAdvertiserAsync -- Message:ADVERTISER_LOGIN_OR_EMAIL_ALREADY_EXIST-- Datetime:{DateTime.Now} " +
                    $"-- UserInfo:{customerForCreationUiModel.CustomerUserLogin}, ");
                return(BadRequest(new { errorMessage = "ADVERTISER_LOGIN_OR_EMAIL_ALREADY_EXIST" }));
            }

            var newCreatedAdvertiser = await _createCustomerProcessor.CreateCustomerAsync(userAudit.Id, customerForCreationUiModel, true);

            switch (newCreatedAdvertiser.Message)
            {
            case ("SUCCESS_CREATION"):
            {
                Log.Information(
                    $"--Method:PostAdvertiserAsync -- Message:ADVERTISER_CREATION_SUCCESSFULLY -- " +
                    $"Datetime:{DateTime.Now} -- AdvertiserInfo:{customerForCreationUiModel.CustomerVat + customerForCreationUiModel.CustomerEmail}");
                return(Created(nameof(PostAdvertiserAsync), newCreatedAdvertiser));
            }

            case ("ERROR_ALREADY_EXISTS"):
            {
                Log.Error(
                    $"--Method:PostAdvertiserAsync -- Message:ERROR_ADVERTISER_ALREADY_EXISTS -- " +
                    $"Datetime:{DateTime.Now} -- AdvertiserInfo:{customerForCreationUiModel.CustomerVat + customerForCreationUiModel.CustomerEmail}");
                return(BadRequest(new { errorMessage = "ADVERTISER_ALREADY_EXISTS" }));
            }

            case ("ERROR_NOT_MADE_PERSISTENT"):
            {
                Log.Error(
                    $"--Method:PostAdvertiserAsync -- Message:ADVERTISER_NOT_MADE_PERSISTENT -- " +
                    $"Datetime:{DateTime.Now} -- AdvertiserInfo:{customerForCreationUiModel.CustomerVat + customerForCreationUiModel.CustomerEmail}");
                return(BadRequest(new { errorMessage = "ERROR_CREATION_NEW_ADVERTISER" }));
            }

            case ("UNKNOWN_ERROR"):
            {
                Log.Error(
                    $"--Method:PostAdvertiserAsync -- Message:ERROR_CREATION_NEW_ADVERTISER -- " +
                    $"Datetime:{DateTime.Now} -- AdvertiserInfo:{customerForCreationUiModel.CustomerVat + customerForCreationUiModel.CustomerEmail}");
                return(BadRequest(new { errorMessage = "ERROR_CREATION_NEW_ADVERTISER" }));
            }
            }

            return(NotFound());
        }
コード例 #4
0
        public async Task <IActionResult> PostRoleRouteAsync([FromBody] RoleForCreationUiModel roleForCreationUiModel)
        {
            var userAudit = await _inquiryUserProcessor.GetUserByLoginAsync(GetEmailFromClaims());

            if (userAudit == null)
            {
                return(BadRequest());
            }

            var newCreatedRole = await _createRoleProcessor.CreateRoleAsync(userAudit.Id, roleForCreationUiModel);

            switch (newCreatedRole.Message)
            {
            case ("SUCCESS_CREATION"):
            {
                Log.Information(
                    $"--Method:PostRoleRouteAsync -- Message:ROLE_CREATION_SUCCESFULLY -- Datetime:{DateTime.Now} -- RoleInfo:{roleForCreationUiModel.Name}");
                return(Created(nameof(PostRoleRouteAsync), newCreatedRole));
            }

            case ("ERRR_ERROR_ALREADY_EXISTS"):
            {
                Log.Error(
                    $"--Method:PostRoleRouteAsync -- Message:ERROR_ROLE_ALREADY_EXISTS -- Datetime:{DateTime.UtcNow} -- RoleInfo:{roleForCreationUiModel.Name}");
                return(BadRequest(new { errorMessage = "ROLE_ALREADY_EXISTS" }));
            }

            case ("ERROR_ROLE_NOT_MADE_PERSISTENT"):
            {
                Log.Error(
                    $"--Method:PostRoleRouteAsync -- Message:ERROR_ROLE_NOT_MADE_PERSISTENT -- Datetime:{DateTime.UtcNow} -- RoleInfo:{roleForCreationUiModel.Name}");
                return(BadRequest(new { errorMessage = "ERROR_CREATION_NEW_ROLE" }));
            }

            case ("UNKNOWN_ERROR"):
            {
                Log.Error(
                    $"--Method:PostRoleRouteAsync -- Message:ERROR_CREATION_NEW_ROLE -- Datetime:{DateTime.UtcNow} -- RoleInfo:{roleForCreationUiModel.Name}");
                return(BadRequest(new { errorMessage = "ERROR_CREATION_NEW_ROLE" }));
            }
            }
            return(NotFound());
        }
コード例 #5
0
        public async Task <IActionResult> PostAdvertisedAsync([FromBody] CustomerForCreationUiModel customerForCreationUiModel)
        {
            var userAudit = await _inquiryUserProcessor.GetUserByLoginAsync(GetEmailFromClaims());

            if (userAudit == null)
            {
                return(BadRequest("AUDIT_USER_NOT_EXIST"));
            }

            var newCreatedAdvertised =
                await _createCustomerProcessor.CreateCustomerAsync(userAudit.Id, customerForCreationUiModel, false);

            switch (newCreatedAdvertised.Message)
            {
            case ("SUCCESS_CREATION"):
            {
                Log.Information(
                    $"--Method:PostAdvertisedAsync -- Message:ADVERTISED_CREATION_SUCCESSFULLY -- " +
                    $"Datetime:{DateTime.Now} -- AdvertisedInfo:{customerForCreationUiModel.CustomerVat + customerForCreationUiModel.CustomerEmail}");
                return(Created(nameof(PostAdvertisedAsync), newCreatedAdvertised));
            }

            case ("ERROR_ALREADY_EXISTS"):
            {
                Log.Error(
                    $"--Method:PostAdvertisedAsync -- Message:ERROR_ADVERTISED_ALREADY_EXISTS -- " +
                    $"Datetime:{DateTime.Now} -- AdvertisedInfo:{customerForCreationUiModel.CustomerVat + customerForCreationUiModel.CustomerEmail}");
                return(BadRequest(new { errorMessage = "CATEGORY_ALREADY_EXISTS" }));
            }

            case ("ERROR_NOT_MADE_PERSISTENT"):
            {
                Log.Error(
                    $"--Method:PostAdvertisedAsync -- Message:ERROR_ADVERTISED_NOT_MADE_PERSISTENT -- " +
                    $"Datetime:{DateTime.Now} -- AdvertisedInfo:{customerForCreationUiModel.CustomerVat + customerForCreationUiModel.CustomerEmail}");
                return(BadRequest(new { errorMessage = "ERROR_CREATION_NEW_CATEGORY" }));
            }

            case ("UNKNOWN_ERROR"):
            {
                Log.Error(
                    $"--Method:PostAdvertisedAsync -- Message:ERROR_CREATION_NEW_ADVERTISED -- " +
                    $"Datetime:{DateTime.Now} -- AdvertisedInfo:{customerForCreationUiModel.CustomerVat + customerForCreationUiModel.CustomerEmail}");
                return(BadRequest(new { errorMessage = "ERROR_CREATION_NEW_ADVERTISED" }));
            }
            }

            return(NotFound());
        }
コード例 #6
0
        public async Task <IActionResult> PostAccountRegisterAsync([FromBody] UserForRegistrationUiModel managedUserVm)
        {
            try
            {
                var userAudit = await _inquiryUserProcessor.GetUserByLoginAsync(GetEmailFromClaims());

                if (userAudit == null)
                {
                    return(BadRequest());
                }

                if (await _inquiryPersonProcessor.SearchIfAnyPersonByEmailOrLoginExistsAsync(managedUserVm.Login))
                {
                    Log.Error(
                        $"--Method:PostAccountRegisterAsync -- Message:USER_REGISTERED_LOGIN_OR_EMAIL_ALREADY_EXIST-- Datetime:{DateTime.Now} " +
                        $"-- UserInfo:{managedUserVm.Login}, ");
                    return(BadRequest(new { errorMessage = "USERNAME_OR_EMAIL_ALREADY_EXISTS" }));
                }

                var registerResponse = await _createUserProcessor.CreateUserAsync(userAudit.Id, managedUserVm);

                switch (registerResponse.Message)
                {
                case ("SUCCESS_CREATION"):
                {
                    Log.Information(
                        $"--Method:PostAccountRegisterAsync -- Message:USER_REGISTERED_SUCCESSFULLY -- Datetime:{DateTime.UtcNow} -- UserInfo:{managedUserVm.Login}");
                    return(Created("/register", new
                        {
                            id = registerResponse.Id,
                            username = managedUserVm.Login,
                            email = managedUserVm.Login,
                            isActivated = false,
                            status = "user created - An activation code was created - Needs Activation"
                        }));
                }

                case ("ERROR_USER_ALREADY_EXISTS"):
                {
                    Log.Error(
                        $"--Method:PostAccountRegisterAsync -- Message:ERROR_USER_ALREADY_EXISTS -- Datetime:{DateTime.UtcNow} -- UserInfo:{managedUserVm.Login}");
                    return(BadRequest(new { errorMessage = "USERNAME_OR_EMAIL_ALREADY_EXISTS" }));
                }

                case ("ERROR_USER_NOT_MADE_PERSISTENT"):
                {
                    Log.Error(
                        $"--Method:PostAccountRegisterAsync -- Message:ERROR_USER_NOT_MADE_PERSISTENT -- Datetime:{DateTime.UtcNow} -- UserInfo:{managedUserVm.Login}");
                    return(BadRequest(new { errorMessage = "ERROR_REGISTER_NEW_USER" }));
                }

                case ("UNKNOWN_ERROR"):
                {
                    Log.Error(
                        $"--Method:PostAccountRegisterAsync -- Message:ERROR_REGISTER_NEW_USER -- Datetime:{DateTime.UtcNow} -- UserInfo:{managedUserVm.Login}");
                    return(BadRequest(new { errorMessage = "ERROR_REGISTER_NEW_USER" }));
                }
                }
            }
            catch (Exception e)
            {
                return(BadRequest(new { errorMessage = e.Message }));
            }

            return(Ok());
        }