public ValidationStatus ValidateRequest(CustomerRequestDTO inputParam)
        {
            if (inputParam != null)
            {
                if (inputParam.Email == null && inputParam.CustomerId == null)
                {
                    return(ValidationStatus.NoInquiryCriteria);
                }
                if (inputParam.CustomerId != null && inputParam.CustomerId < 0)
                {
                    return(ValidationStatus.InvalidCustomerId);
                }
                if (inputParam.Email != null)
                {
                    if (inputParam.Email.Length == 0 || !IsValidEmail(inputParam.Email))
                    {
                        return(ValidationStatus.InvalidEmail);
                    }
                }
                else
                {
                    if (inputParam.CustomerId == 0)
                    {
                        return(ValidationStatus.InvalidCustomerId);
                    }
                }

                return(ValidationStatus.Success);
            }
            else
            {
                return(ValidationStatus.NoInquiryCriteria);
            }
        }
Пример #2
0
        public async Task <CustomerResponseDTO> CreateAsync(CustomerRequestDTO customer)
        {
            var customerModel   = _mapper.Map <CustomerModel>(customer);
            var createdCustomer = _repository.Create(customerModel);

            await _repository.SaveChangesAsync();

            return(_mapper.Map <CustomerResponseDTO>(createdCustomer));
        }
Пример #3
0
        public async Task <IActionResult> GetAccountList([FromQuery] CustomerRequestDTO customerRequest)
        {
            var accList = await _accountQueryService.GetAllUser();

            return(Json(new
            {
                data = accList,
                itemsCount = accList.Count
            }));
        }
Пример #4
0
        public async Task <IActionResult> GetCustomerList([FromQuery] CustomerRequestDTO customerRequest)
        {
            var customerList = await _customerQueryService.GetAllCustomer();

            return(Json(new
            {
                data = customerList,
                itemsCount = customerList.Count
            }));
        }
Пример #5
0
        public async Task <CustomerResponseDTO> FullUpdateAsync(long id, CustomerRequestDTO customer)
        {
            var currentCustomer = await _repository.FindByIdAsync(id);

            if (currentCustomer == null)
            {
                throw new CustomerNotFoundException(String.Format("Customer with the id '{0}' was not found", id));
            }

            var updatedCustomer = _mapper.Map(customer, currentCustomer);

            await _repository.SaveChangesAsync();

            return(_mapper.Map <CustomerResponseDTO>(updatedCustomer));
        }
        public void Execute(int search, CustomerRequestDTO request)
        {
            var customer = AiContext.Customers.Find(search);

            if (customer == null || customer.IsDeleted == 1)
            {
                throw new EntityNotFoundException("Customer");
            }
            customer.FirstName   = request.FirstName;
            customer.LastName    = request.LastName;
            customer.Email       = request.Email;
            customer.PhoneNumber = request.PhoneNumber;
            customer.Birthday    = request.Birthday;
            customer.ModifiedAt  = DateTime.Now;
            AiContext.SaveChanges();
        }
        public CustomerDTO GetCustomer(CustomerRequestDTO inputParam)
        {
            CustomerDBEntities db       = new CustomerDBEntities();
            CustomerDTO        customer = null;

            #region AutoMapper intialization
            var config = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <Customer, CustomerDTO>();
                cfg.CreateMap <Transaction, TransactionDTO>()
                .ForMember(vm => vm.Id, m => m.MapFrom(u => u.TransactionId))
                .ForMember(vm => vm.Date, m => m.MapFrom(u => u.TransactionDate.ToString("g", DateTimeFormatInfo.InvariantInfo)));
            });
            IMapper mapper = config.CreateMapper();
            #endregion

            #region Search Criteria
            if (inputParam.CustomerId > 0 && inputParam.Email != null && inputParam.Email.Length > 0)
            {
                var dbResult = db.Customers.Where(x => x.CustomerId == inputParam.CustomerId &&
                                                  x.Email == inputParam.Email).FirstOrDefault();
                if (dbResult != null)
                {
                    customer = mapper.Map <Customer, CustomerDTO>(dbResult);
                }
            }
            else if (inputParam.Email != null && inputParam.Email.Length > 0)
            {
                var dbResult = db.Customers.Where(x => x.Email == inputParam.Email).FirstOrDefault();
                if (dbResult != null)
                {
                    customer = mapper.Map <Customer, CustomerDTO>(dbResult);
                }
            }
            else if (inputParam.CustomerId > 0)
            {
                var dbResult = db.Customers.Where(x => x.CustomerId == inputParam.CustomerId).FirstOrDefault();
                if (dbResult != null)
                {
                    customer = mapper.Map <Customer, CustomerDTO>(dbResult);
                }
            }
            #endregion

            return(customer);
        }
        public async Task <ActionResult <CustomerResponseDTO> > CreateAsync(CustomerRequestDTO customer)
        {
            CustomerResponseDTO createdCustomer;

            try
            {
                createdCustomer = await _service.CreateAsync(customer);
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message);
                _logger.LogError(e.StackTrace);
                return(StatusCode(500));
            }

            return(CreatedAtRoute("FindCustomerById", new { id = createdCustomer.Id }, createdCustomer));
        }
Пример #9
0
        public async Task <IActionResult> UpdateCustomer([FromBody] CustomerRequestDTO request)
        {
            Customer _customer = new Customer();

            _customer            = Mapper.Map(request, _customer);
            _customer.UpdateDate = DateTime.Now;
            _customer.delFlag    = false;

            bool result = await _customerQueryService.UpdateCustomer(_customer);

            if (result)
            {
                return(Ok(new
                {
                    status = "success"
                }));
            }

            return(BadRequest("Error"));
        }
 public IActionResult Put(int id, [FromBody] CustomerRequestDTO dto)
 {
     try
     {
         _updateCustomer.Execute(id, dto);
         return(NoContent());
     }
     catch (EntityNotFoundException e)
     {
         return(NotFound(e.Message));
     }
     catch (EntityExistsException e)
     {
         return(Conflict(e.Message));
     }
     catch (Exception)
     {
         return(StatusCode(500, "Server error"));
     }
 }
 public ActionResult <CustomerResponseDTO> Post([FromBody] CustomerRequestDTO customer)
 {
     try
     {
         var result = _insertCustomer.Execute(customer);
         return(Created("api/users/" + result.Id, result));
     }
     catch (EntityNotFoundException e)
     {
         return(NotFound(e.Message));
     }
     catch (EntityExistsException e)
     {
         return(Conflict(e.Message));
     }
     catch (Exception)
     {
         return(StatusCode(500, "ServerError"));
     }
 }
        public CustomerResponseDTO Execute(CustomerRequestDTO request)
        {
            var customer = new Customer();

            customer.FirstName   = request.FirstName;
            customer.LastName    = request.LastName;
            customer.Email       = request.Email;
            customer.PhoneNumber = request.PhoneNumber;
            customer.Birthday    = request.Birthday;
            AiContext.Customers.Add(customer);
            AiContext.SaveChanges();
            return(new CustomerResponseDTO
            {
                Id = customer.Id,
                FirstName = customer.FirstName,
                LastName = customer.LastName,
                Email = customer.Email,
                PhoneNumber = customer.PhoneNumber,
                Birthday = customer.Birthday
            });
        }
Пример #13
0
        public HttpResponseMessage GetCustomer([FromBody] CustomerRequestDTO inputParam)
        {
            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, "Not found");

            try
            {
                ICustomerBAL customerBAL = new CustomerBAL();
                switch (customerBAL.ValidateRequest(inputParam))
                {
                case ValidationStatus.Success:
                    var output = customerBAL.GetCustomer(inputParam);
                    if (output != null)
                    {
                        response = Request.CreateResponse(HttpStatusCode.OK, output);
                    }
                    break;

                case ValidationStatus.BadRequest:
                    response = Request.CreateResponse(HttpStatusCode.BadRequest, "");
                    break;

                case ValidationStatus.InvalidCustomerId:
                    response = Request.CreateResponse(HttpStatusCode.BadRequest, "Invalid Customer Id");
                    break;

                case ValidationStatus.InvalidEmail:
                    response = Request.CreateResponse(HttpStatusCode.BadRequest, "Invalid Email");
                    break;

                case ValidationStatus.NoInquiryCriteria:
                    response = Request.CreateResponse(HttpStatusCode.BadRequest, "No inquiry criteria");
                    break;
                }
            }
            catch (Exception)
            {
                response = Request.CreateResponse(HttpStatusCode.BadRequest, "");
            }
            return(response);
        }
        public async Task <ActionResult <CustomerResponseDTO> > FullUpdateAsync(long id, CustomerRequestDTO customer)
        {
            CustomerResponseDTO updatedCustomer;

            try
            {
                updatedCustomer = await _service.FullUpdateAsync(id, customer);
            }
            catch (CustomerNotFoundException)
            {
                return(NotFound());
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message);
                _logger.LogError(e.StackTrace);
                return(StatusCode(500));
            }

            return(Ok(updatedCustomer));
        }