public int UpdateCustomer(CustomerAcctDetails customer)
        {
            try
            {
                using (_dbContext = string.IsNullOrEmpty(_connectionString) ? _dbContext : new ZionContext(_connectionString))
                {
                    _dbContext.Entry(customer).State = EntityState.Modified;

                    if (customer.Status == "Inactive") //Deactivate all the dependent objects
                    {
                        InterfaceMasterDataAccess interfaceDAL = new InterfaceMasterDataAccess(_connectionString);
                        List <InterfaceMaster>    interfaces   = _dbContext.InterfaceMaster.Where(intf => intf.CustomerId == customer.CustomerId && intf.Status != "Inactive").ToList();

                        if (interfaces != null && interfaces.Count > 0)
                        {
                            _dbContext.AttachRange(interfaces);
                            interfaces.ForEach(intf =>
                            {
                                intf.Status = customer.Status;
                                interfaceDAL.UpdateInterfaceHeirarchyStatus(_dbContext, intf.InterfaceId, "Inactive");
                            }
                                               );
                        }
                    }

                    _dbContext.SaveChanges();

                    return(1);
                }
            }
            catch
            {
                throw;
            }
        }
        public void given_new_customer_when_created_then_verify_customer_created(int input1)
        {
            CustomerAcctDetails custDetails = CustomerAcctDetailsParam.GetSingle(input1); // new Fixture().Create<CustomerAcctDetails>();

            _manager.Setup(x => x.AddCustomer(It.IsAny <CustomerAcctDetails>())).Returns(1);

            var result = _controller.Create(custDetails);

            Assert.Equal(1, result);
        }
        public void given_customer_id_when_fetched_then_returns_customer_details(int input1)
        {
            CustomerAcctDetails custDetails = CustomerAcctDetailsParam.GetSingle(input1); // new Fixture().Create<CustomerAcctDetails>();

            _manager.Setup(x => x.GetCustomerData(custDetails.CustomerId)).Returns(custDetails);

            var result = _controller.Details(custDetails.CustomerId);

            Assert.NotNull(result);
            Assert.Equal(custDetails, result);
        }
        public void given_customer_when_updated_then_verify_the_changes(int input1)
        {
            CustomerAcctDetails custDetails = CustomerAcctDetailsParam.GetSingle(input1);

            custDetails.PhoneNumber = "04425984656";

            _manager.Setup(x => x.UpdateCustomer(custDetails)).Returns(1);

            var result = _controller.Edit(custDetails);

            Assert.Equal(1, result);
        }
 public CustomerAcctDetails GetCustomerData(int id)
 {
     try
     {
         using (_dbContext = string.IsNullOrEmpty(_connectionString) ? _dbContext : new ZionContext(_connectionString))
         {
             CustomerAcctDetails customer = _dbContext.CustomerAcctDetails.Find(id);
             return(customer);
         }
     }
     catch
     {
         throw;
     }
 }
 public int AddCustomer(CustomerAcctDetails customer)
 {
     try
     {
         using (_dbContext = string.IsNullOrEmpty(_connectionString) ? _dbContext : new ZionContext(_connectionString))
         {
             _dbContext.CustomerAcctDetails.Add(customer);
             _dbContext.SaveChanges();
             return(1);
         }
     }
     catch
     {
         throw;
     }
 }
 public int DeleteCustomer(int id)
 {
     try
     {
         using (_dbContext = string.IsNullOrEmpty(_connectionString) ? _dbContext : new ZionContext(_connectionString))
         {
             CustomerAcctDetails emp = _dbContext.CustomerAcctDetails.Find(id);
             _dbContext.CustomerAcctDetails.Remove(emp);
             _dbContext.SaveChanges();
             return(1);
         }
     }
     catch
     {
         throw;
     }
 }
 public int Edit([FromBody] CustomerAcctDetails customer)
 {
     return(_customerManager.UpdateCustomer(customer));
 }