public RemovedCustomer(DbRemovedCustomer dbRemovedCustomer)
 {
     RemovedCustomerId = dbRemovedCustomer.DbRemovedCustomerId;
     DateRemoved       = dbRemovedCustomer.DateRemoved;
     RemovedByUser     = new User(dbRemovedCustomer.DbRemovedByUser);
     Customer          = new Customer(dbRemovedCustomer.DbCustomer);
 }
Exemple #2
0
        public RemovedCustomer RemoveCustomer(RemovedCustomer removedCustomer)
        {
            var dbContext = new DataContext();

            var dbRemovedCustomerFound = dbContext.DbRemovedCustomers.FirstOrDefault(dbRemovedCustomer => dbRemovedCustomer.DbCustomer.DbCustomerId == removedCustomer.Customer.CustomerId);

            if (dbRemovedCustomerFound == null)
            {
                dbRemovedCustomerFound                     = new DbRemovedCustomer();
                dbRemovedCustomerFound.DateRemoved         = removedCustomer.DateRemoved;
                dbRemovedCustomerFound.DbRemovedCustomerId = removedCustomer.RemovedCustomerId;
                dbRemovedCustomerFound.DbCustomer          = GetDbCustomer(dbContext, removedCustomer.Customer.CustomerId);
                dbRemovedCustomerFound.DbRemovedByUser     = new UsersRepository().GetDbUser(dbContext, removedCustomer.RemovedByUser.UserId);

                dbRemovedCustomerFound = dbContext.DbRemovedCustomers.Add(dbRemovedCustomerFound);
                dbContext.SaveChanges();
            }


            return(new RemovedCustomer(dbRemovedCustomerFound));
        }