Exemplo n.º 1
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());
        }
Exemplo n.º 2
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());
        }