Example #1
0
        public void TestUpdateLogoutDate_ValidToken_LogoutDateShouldBeUpdated()
        {
            #region Arrange
            int                customerId = 572845;
            string             callerId   = "Portal";
            string             tokenMd5   = "a43b38e70c75d1ed8ef9c47f5de2833b";
            UserAuthentication hppAuth    = new UserAuthentication()
            {
                UserId       = customerId,
                CallerId     = callerId,
                TokenMD5     = tokenMd5,
                CountryCode  = "en",
                LanguageCode = "US"
            };
            queryUtilsMock.Setup(x => x.GetHPPToken(It.IsAny <IIdeaDatabaseDataContext>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>()))
            .Returns(hppAuth);
            #endregion Arrange

            #region Act
            ResponseBase  response  = new ResponseBase();
            CustomerUtils custUtils = new CustomerUtils();
            custUtils.UpdateLogoutDate(response, customerId, callerId, tokenMd5);
            #endregion Act

            #region Assert
            Assert.AreEqual(0, response.ErrorList.Count, "Unexpected fault encountered");
            databaseMock.Verify(x => x.SubmitChanges(), Times.Exactly(1));
            #endregion Assert
        }
Example #2
0
        public IActionResult UpdateInfo([FromBody] Customer customer, int id)
        {
            if (customer == null)
            {
                var newCustUtil = new CustomerUtils();

                var item = newCustUtil.GetCustomerById(id);

                if (item == null)
                {
                    return(NotFound("Customer Was Not Found"));
                }

                return(new ObjectResult(item));
            }
            else
            {
                var newCustUtil = new CustomerUtils();
                customer.CustomerId = id;
                try
                {
                    var result = newCustUtil.UpdateCustomer(customer);

                    if (result)
                    {
                        return(NoContent());
                    }
                    return(BadRequest($"Couldn't Update Customer!"));
                }
                catch (Exception e)
                {
                    return(BadRequest($"Couldn't Update Customer!" + e));
                }
            }
        }
Example #3
0
        public void When_He_Has_Credit_Limit_Then_Return_True()
        {
            _mockCustomer.HasCreditLimit = true;
            var result = CustomerUtils.IsLimtedCredit(_mockCustomer);

            Assert.AreEqual(true, result);
        }
Example #4
0
        public IActionResult Get(JObject data)
        {
            Customer     customer    = JsonConvert.DeserializeObject <Customer>(data.ToString());
            List <Order> queryResult = OrderUtils.QueryOrder((order) => {
                return(CustomerUtils.CompareCustomer(order.customer, customer));
            });

            return(queryResult.Count >= 1 ?
                   (ActionResult) new OkObjectResult(JsonConvert.SerializeObject(queryResult, Formatting.Indented)) :
                   new BadRequestObjectResult("No result found"));
        }
        public IActionResult GetById(int id)
        {
            var newCustUtil = new CustomerUtils();

            var item = newCustUtil.GetCustomerById(id);

            if (item == null)
            {
                return(NotFound("Customer Was Not Found"));
            }

            return(new ObjectResult(item));
        }
Example #6
0
        public IActionResult Search([FromBody] CustomerSearchInfo searchInfo)
        {
            var searchResults    = new List <Customer>();
            var newCustomerUtils = new CustomerUtils();

            searchResults = newCustomerUtils.SearchCustomers(searchInfo);

            if (searchResults.Count >= 1)
            {
                return(new ObjectResult(searchResults));
            }

            return(NotFound("No Results were found given the search terms entered!"));
        }
Example #7
0
        public IActionResult DeleteCustomer(int id)
        {
            try
            {
                var newCustUtil = new CustomerUtils();
                if (newCustUtil.MakeCustomerInactive(id))
                {
                    return(NoContent());
                }

                return(NotFound($"Couldnt find the Customer {id} you specified!"));
            }
            catch (Exception e)
            {
                return(NotFound($"Couldnt find the Customer {id} you specified!" + e));
            }
        }
Example #8
0
        public bool AddCustomer(Customer customerInfo)
        {
            if (!ValidateCustomInfo(customerInfo))
            {
                return(false);
            }

            var company = _companyRepository.GetById(customerInfo.CompanyId);

            var customer = InitCustomer(customerInfo, company);

            this.GetCustomerCredit(company, customer);

            if (CustomerUtils.IsLimtedCredit(customer))
            {
                return(false);
            }

            _customerDataAccess.AddCustomer(customer);

            return(true);
        }
        public IActionResult Create([FromBody] Customer newCustInfo)
        {
            var newCustUtil = new CustomerUtils();

            newCustInfo.AccountBalance = 0;
            newCustInfo.Active         = true;

            try
            {
                var newCustomerKey = new ReturnedKey();
                newCustomerKey.Key = newCustUtil.MakeNewCustomer(newCustInfo);
                if (newCustomerKey.Key > -1)
                {
                    return(Ok(newCustomerKey));
                }
                return(BadRequest("Error, Customer Couldnt be created!"));
            }
            catch (Exception e)
            {
                return(StatusCode(500, "Error, Customer Couldnt be created! " + e));
            }
        }
        public IActionResult UpdateInfo([FromBody] Customer customer)
        {
            var newCustUtil = new CustomerUtils();

            try
            {
                var result = newCustUtil.UpdateCustomer(customer);

                if (result)
                {
                    //SUCCESS
                    _context.Customers.Add(customer);
                    _context.SaveChanges();
                    return(CreatedAtRoute("GetCustomer", new { id = customer.CustomerId }, customer));
                }
                return(BadRequest($"Couldn't Update Customer!"));
            }
            catch (Exception e)
            {
                return(BadRequest($"Couldn't Update Customer!" + e));
            }
        }
 protected override void Merge(Customer source, Customer target)
 {
     CustomerUtils.Merge(source, target);
 }
 protected override QueryFilters <CustomerProperty> GetChanges(Customer original, Customer changed)
 {
     return(CustomerUtils.GetChanges(original, changed));
 }