Ejemplo n.º 1
0
        public async Task <CustomerRegistrationResponse> DeleteCustomerAsync(Guid id)
        {
            try
            {
                var responseDelete = new CustomerRegistrationResponse
                {
                    Response = "Customer Details deleted successfully",
                };
                GenericRepository <Customer> generic = new GenericRepository <Customer>(_context, this.dbSet, _httpContextAccessor);
                var customer = await generic.DeleteCustomer(id);

                if (customer != null)
                {
                    _context.Customers.Remove(customer);
                    await _context.SaveChangesAsync();
                }
                return(responseDelete);
            }
            catch (Exception ex)
            {
                var responseError = new CustomerRegistrationResponse
                {
                    Response = ex.Message,
                };
                return(responseError);

                throw ex;
            }
        }
Ejemplo n.º 2
0
        public async Task <CustomerRegistrationResponse> RegisterAgentAsync(AgentDto agent)
        {
            try
            {
                var customer = new Customer
                {
                    Id               = GenerateGuid().Result,
                    MainAddressId    = GenerateGuid().Result,
                    Firstname        = agent.Firstname,
                    Lastname         = agent.Lastname,
                    AgentBank        = agent.AgentBank,
                    AgentName        = agent.Firstname + " " + agent.Lastname,
                    AgentUserName    = agent.AgentUserName,
                    Dob              = agent.Dob,
                    IsAgent          = true,
                    Email            = agent.Email,
                    Password         = agent.Password,
                    Fax              = agent.Fax,
                    Gender           = agent.Gender,
                    IsCustomer       = false,
                    NewsLetterOpted  = false,
                    CustomerUserName = null,
                    Telephone        = agent.Telephone
                };
                GenericRepository <Customer> generic = new GenericRepository <Customer>(_context, this.dbSet, _httpContextAccessor);
                if (_context.Customers.Any(c => c.Email == customer.Email || c.AgentBank == customer.AgentBank || c.AgentUserName == customer.AgentUserName))
                {
                    var responseEmailExist = new CustomerRegistrationResponse
                    {
                        Response = "The Credentials supplied already exist",
                    };
                    return(responseEmailExist);
                }
                var responseSuccess = new CustomerRegistrationResponse
                {
                    Response = "Agent Details successfully added",
                };
                await generic.PostCustomer(customer);

                await _context.SaveChangesAsync();

                return(responseSuccess);
            }
            catch (Exception ex)
            {
                var responseException = new CustomerRegistrationResponse
                {
                    Response = ex.Message,
                };
                return(responseException);

                throw ex;
            }
        }
Ejemplo n.º 3
0
        public async Task <CustomerRegistrationResponse> RegisterCustomerAsync(CustomerDto customerdto)
        {
            try
            {
                var customer = new Customer
                {
                    Id               = GenerateGuid().Result,
                    MainAddressId    = GenerateGuid().Result,
                    Firstname        = customerdto.Firstname,
                    Lastname         = customerdto.Lastname,
                    CustomerUserName = customerdto.Firstname + " " + customerdto.Lastname,
                    IsCustomer       = true,
                    Dob              = customerdto.Dob,
                    Email            = customerdto.Email,
                    Gender           = customerdto.Gender,
                    Fax              = customerdto.Fax,
                    IsAgent          = false,
                    NewsLetterOpted  = true,
                    Password         = customerdto.Password,
                    Telephone        = customerdto.Telephone
                };
                GenericRepository <Customer> generic = new GenericRepository <Customer>(_context, this.dbSet, _httpContextAccessor);

                if (_context.Customers.Any(c => c.Email == customer.Email))
                {
                    var responseEmailExist = new CustomerRegistrationResponse
                    {
                        Response = "Customer email already exist",
                    };
                    return(responseEmailExist);
                }
                var responseSuccess = new CustomerRegistrationResponse
                {
                    Response = "Customer Details successfully added",
                };
                await generic.PostCustomer(customer);

                await _context.SaveChangesAsync();

                return(responseSuccess);
            }
            catch (Exception ex)
            {
                var responseException = new CustomerRegistrationResponse
                {
                    Response = ex.Message,
                };
                return(responseException);

                throw ex;
            }
        }
Ejemplo n.º 4
0
        public IActionResult RegisterCustomer(CustomerRegistrationRequest request)
        {
            var validator = new CustomerRegistrationRequestValidator();
            var results   = validator.Validate(request);

            if (results.IsValid)
            {
                // save the details to the db
                var response = new CustomerRegistrationResponse();
                // todo: set the Id in the response based on the db record id
                return(Ok(response));
            }
            else
            {
                var response = new CustomerRegistrationResponse
                {
                    Errors = results.Errors.Select(x => x.ErrorMessage).ToArray()
                };
                return(BadRequest(response));
            }
        }
Ejemplo n.º 5
0
        public async Task <CustomerRegistrationResponse> RegisterAdditionalProduct(Customer customer)
        {
            Log.Verbose("Requesting additonal product");
            ServerResponse <CustomerRegistrationResponse> responseObj = await PostObjectAsync <CustomerRegistrationResponse, Customer>(customer);

            if (responseObj == null)
            {
                Log.Verbose("API CALL NOT successfull");

                return(new CustomerRegistrationResponse()
                {
                    Customer = null,
                    RequestId = customer.RequestId,
                    Successful = false,
                    RegistrationSuccessful = false,
                    ResponseText = null
                });
            }

            Log.Verbose("API Response " + responseObj.IsSuccessStatus);
            Log.Verbose(responseObj.RawResponse);

            // try getting the object from JSON
            CustomerRegistrationResponse response = null;

            try
            {
                response = responseObj.GetObject();
            }
            catch (Exception e)
            {
                Log.Error(e);
            }

            // got a proper result, return it
            if (response != null)
            {
                response.Successful = true;
                return(response);
            }

            Log.Verbose("Could not parse response.");

            // if exception was thrown, return the exception as text
            if (responseObj.RequestException != null)
            {
                return(new CustomerRegistrationResponse()
                {
                    Customer = null,
                    RequestId = customer.RequestId,
                    Successful = false,
                    RegistrationSuccessful = false,
                    ResponseText = responseObj.RequestException.ToString()
                });
            }

            return(new CustomerRegistrationResponse()
            {
                Customer = null,
                RequestId = customer.RequestId,
                Successful = false,
                RegistrationSuccessful = false,
                ResponseText = "Unknown Error."
            });
        }
Ejemplo n.º 6
0
        private async Task <bool> AttemptDataRegistration(BL.Models.People.Customer customer)
        {
            if (!Resolver.Instance.Get <IConnectivityService>().HasConnection())
            {
                return(false);
            }

            // try to post the person via the API, for configurable x tries
            CustomerRegistrationResponse response = null;
            int apiTries = 1;

            while (apiTries <= this.numberOfRetries)
            {
                Log.Verbose("API register try " + apiTries);

                // call the API and await response
                response = await this.RegisterViaApi(customer);

                response.Customer = customer;

                if (response.Successful)
                {
                    this.RegistrationSuccessful = true;

                    if (response.RegistrationId != Guid.Empty)
                    {
                        var registrationCompletedEventArgs = new CustomerRegistrationCompletedEventArgs(
                            DataChannel.Full,
                            true)
                        {
                            RegistrationId = response.RegistrationId
                        };

                        this.FireRegistrationCompleted(registrationCompletedEventArgs);
                    }
                    else
                    {
                        this.FireRegistrationCompleted(DataChannel.Full, true);
                    }

                    return(true);
                }

                this.FireRegistrationAttempted(DataChannel.Full, apiTries);

                // exception on reported 500 error, do not continue
                if (response.ResponseText.Equals("HttpResponse500Exception"))
                {
                    Log.Error("API threw 500 error (HttpResponse500Exception).");
                    break;
                }

                // next retry
                apiTries++;
            }

            // make sure the warning logging never fails, it is extra information
            try
            {
                var responseText = response == null ? "response=null" : response.ResponseText;
                Log.Warning("Fallback Registration: Attempts to register via Internet failed. ResponseText = " +
                            responseText);
            }
            catch (Exception e)
            {
                Log.Error(e);
            }


            return(false);
        }
Ejemplo n.º 7
0
        public async Task <CustomerRegistrationResponse> UpdateCustomerAsync(Guid id, Customer customer)
        {
            try
            {
                var customers = GetCustomerBeforeAsync(id);
                if (customers.Result == null)
                {
                    var resp = new CustomerRegistrationResponse
                    {
                        StatusCode     = "33",
                        ResponseStatus = "no content",
                        Response       = "The User id is not valid"
                    };
                    return(resp);
                }
                if (!string.IsNullOrEmpty(customer.Firstname))
                {
                    customers.Result.Firstname = customer.Firstname;
                }
                if (!string.IsNullOrEmpty(customer.Lastname))
                {
                    customers.Result.Lastname = customer.Lastname;
                }
                if (!string.IsNullOrEmpty(customer.Telephone))
                {
                    customers.Result.Telephone = customer.Telephone;
                }
                if (!string.IsNullOrEmpty(customer.Gender))
                {
                    customers.Result.Gender = customer.Gender;
                }
                if (!string.IsNullOrEmpty(customer.Email))
                {
                    customers.Result.Email = customer.Email;
                }
                if (!string.IsNullOrEmpty(customer.Fax))
                {
                    customers.Result.Fax = customer.Fax;
                }
                if (!string.IsNullOrEmpty(customer.MainAddressId.ToString()))
                {
                    customers.Result.MainAddressId = customer.MainAddressId;
                }
                GenericRepository <Customer> generic = new GenericRepository <Customer>(_context, this.dbSet, _httpContextAccessor);
                await generic.UpdateCustomerAsync(id, customer);

                var updateResponse = new CustomerRegistrationResponse
                {
                    Response       = "Customer Record Updated Successfully",
                    StatusCode     = "00",
                    ResponseStatus = "success"
                };
                return(updateResponse);
            }
            catch (Exception ex)
            {
                var updateErro = new CustomerRegistrationResponse
                {
                    Response       = "Customer Details was not updated",
                    StatusCode     = "01",
                    ResponseStatus = "failed"
                };
                return(updateErro);

                throw ex;
            }
        }