static void Main(string[] args)
        {
            IUnitOfwork  unitOfwork  = new UnitOfwork(new rentalEntities());
            ICopiesLogic moviesLogic = new CopiesLogic(unitOfwork);

            var result = moviesLogic.GetAll();
        }
        public void CreateCorrectlyCharacterService_IfEfRepositoryIsNotNull()
        {
            var dbContext  = new EfMarvelCatalogDbContext();
            var unitOfWork = new UnitOfwork(dbContext);
            var repository = new EfRepository <CharacterDataModel>(dbContext);

            Assert.DoesNotThrow(() => new CharacterService(unitOfWork, repository));
        }
        public void ThrowArgumentNullEcpetion_WhenIsPassedInvalidEfRepository()
        {
            // Arrange
            var dbContext  = new EfMarvelCatalogDbContext();
            var unitOfWork = new UnitOfwork(dbContext);

            // Act & Assert
            Assert.Throws <ArgumentNullException>(() => new CharacterService(unitOfWork, null));
        }
        public void CreateInstance_OfTypeICharacterService()
        {
            var dbContext  = new EfMarvelCatalogDbContext();
            var unitOfWork = new UnitOfwork(dbContext);
            var repository = new EfRepository <CharacterDataModel>(dbContext);

            var characterService = new CharacterService(unitOfWork, repository);

            Assert.IsInstanceOf <ICharacterService>(characterService);
        }
Exemple #5
0
        public void RouteADF()
        {
            var UnitOfWork = new UnitOfwork();
            var Service    = new Case1Service(UnitOfWork);

            var mockData = "A-D-F";
            var output   = Service.CalculateDeliveryCost(mockData);

            //Assert
            Assert.True(output == 0, "Output was not equal 0");
        }
        public void CreateInstance_OfTypeIUnitOfWork()
        {
            // Arrange
            var dbContext = new EfMarvelCatalogDbContext();

            // Act
            var unitOfWork = new UnitOfwork(dbContext);

            // Assert
            Assert.IsInstanceOf <IUnitOfWork>(unitOfWork);
        }
Exemple #7
0
        public void RouteABEInputIsLower()
        {
            var UnitOfWork = new UnitOfwork();
            var Service    = new Case1Service(UnitOfWork);

            var mockData = "a-b-e";
            var output   = Service.CalculateDeliveryCost(mockData);

            //Assert
            Assert.True(output == 4, "Output was not equal 4");
        }
Exemple #8
0
        public void RouteEToEInputIsLower()
        {
            var UnitOfWork = new UnitOfwork();
            var Service    = new Case3Service(UnitOfWork);

            var mockDataStart = "e";
            var mockDataEnd   = "e";
            var output        = Service.CalculateCheapestDeliveryCost(mockDataStart, mockDataEnd);

            //Assert
            Assert.True(output == 6, "Output was not equal 6");
        }
Exemple #9
0
        public void RouteABE()
        {
            var UnitOfWork    = new UnitOfwork();
            var Service       = new Case2Service(UnitOfWork);
            var mockDataStart = "E";
            var mockDataEnd   = "D";
            var mockMaximum   = 4;
            var output        = Service.GetPossibleDeliveryRouteWithMaximum(mockDataStart, mockDataEnd, mockMaximum);

            //Assert
            Assert.True(output == 4, "Output was not equal 4");
        }
        public OrderDetailEditModels CreateOrderDetail(OrderDetailEditModels model, out string message)
        {
            var ship = _OrderDetailRepository.getOrderDetail(model.OrderId, model.ProductId);

            if (ship != null)
            {
                message = Constants.OrderDetailIsExist;
                return(null);
            }
            var CreateOrderDetail = _OrderDetailRepository.Insert(model.MapToEditEntity());

            UnitOfwork.SaveChanges();
            if (CreateOrderDetail == null)
            {
                message = Constants.CreateFail;
                return(null);
            }
            message = Constants.CreateSuccess;
            return(CreateOrderDetail.MapToEditModel());
        }
Exemple #11
0
        public CustomerListModels CreateCustomer(CustomerListModels model, out string message)
        {
            var ship = _CustomerRepository.getCustomer(model.CustomerId, model.ContactName, model.CompanyName);

            if (ship != null)
            {
                message = Constants.CustomerIsExist;
                return(null);
            }
            var CreateCustomer = _CustomerRepository.Insert(model.MapToEntity());

            UnitOfwork.SaveChanges();
            if (CreateCustomer == null)
            {
                message = Constants.CreateFail;
                return(null);
            }
            message = Constants.CreateSuccess;
            return(CreateCustomer.MapToModel());
        }
Exemple #12
0
        public EmployeeEditModels CreateEmployee(EmployeeEditModels model, out string message)
        {
            var ship = _EmployeeRepository.getEmployee(model.EmployeeId, model.FirstName, model.LastName);

            if (ship != null)
            {
                message = Constant.EmployeeIsExist;
                return(null);
            }
            var CreateEmployee = _EmployeeRepository.Insert(model.MapToEditEntity());

            UnitOfwork.SaveChanges();
            if (CreateEmployee == null)
            {
                message = Constant.CreateFail;
                return(null);
            }
            message = Constant.CreateSuccess;
            return(CreateEmployee.MapToEditModel());
        }
Exemple #13
0
        public ShipperEditModels CreateShipper(ShipperEditModels model, out string message)
        {
            var ship = _ShipperRepository.getshipper(model.ShipperId, model.CompanyName, model.Phone);

            if (ship != null)
            {
                message = Constant.ShipperIsExist;
                return(null);
            }
            var CreateShipper = _ShipperRepository.Insert(model.MapToEditEntity());

            UnitOfwork.SaveChanges();
            if (CreateShipper == null)
            {
                message = Constant.CreateFail;
                return(null);
            }
            message = Constant.CreateSuccess;
            return(CreateShipper.MapToEditModel());
        }
Exemple #14
0
        public OrderEditModels CreateOrder(OrderEditModels model, out string message)
        {
            var ship = _OrderRepository.getOrder(model.OrderId, model.CustomerId, model.EmployeeId);

            if (ship != null)
            {
                message = Constants.OrderIsExist;
                return(null);
            }
            var CreateOrder = _OrderRepository.Insert(model.MapToEditEntity());

            UnitOfwork.SaveChanges();
            if (CreateOrder == null)
            {
                message = Constants.CreateFail;
                return(null);
            }
            message = Constants.CreateSuccess;
            return(CreateOrder.MapToEditModel());
        }
Exemple #15
0
        public CategoryEditModels CreateCategory(CategoryEditModels model, out string message)
        {
            var ship = _CategoryRepository.getCategory(model.CategoryId, model.CategoryName);

            if (ship != null)
            {
                message = Constant.CategoryIsExist;
                return(null);
            }
            var CreateCategory = _CategoryRepository.Insert(model.MapToEditEntity());

            UnitOfwork.SaveChanges();
            if (CreateCategory == null)
            {
                message = Constant.CreateFail;
                return(null);
            }
            message = Constant.CreateSuccess;
            return(CreateCategory.MapToEditModel());
        }
Exemple #16
0
        public ProductEditModels CreateProduct(ProductEditModels model, out string message)
        {
            var ship = _ProductRepository.getProduct(model.ProductId, model.ProductName);

            if (ship != null)
            {
                message = Constants.ProductIsExist;
                return(null);
            }
            var CreateProduct = _ProductRepository.Insert(model.MapToEditEntity());

            UnitOfwork.SaveChanges();
            if (CreateProduct == null)
            {
                message = Constants.CreateFail;
                return(null);
            }
            message = Constants.CreateSuccess;
            return(CreateProduct.MapToEditModel());
        }
Exemple #17
0
        public bool UpdateOrderDetail(OrderDetailEditModels model, out string message)
        {
            var OrderDetailEntity = _OrderDetailRepository.GetById(model.OrderId);

            if (OrderDetailEntity != null)
            {
                var gr = _OrderDetailRepository.getOrderDetail(model.OrderId, model.ProductId);
                if (gr != null)
                {
                    message = Constant.OrderDetailIsExist;
                    return(false);
                }
                OrderDetailEntity = model.MapToEditEntity(OrderDetailEntity);
                _OrderDetailRepository.Update(OrderDetailEntity);
                UnitOfwork.SaveChanges();
                message = Constant.UpdateSuccess;
                return(true);
            }
            message = Constant.UpdateFail;
            return(false);
        }
Exemple #18
0
        public bool UpdateShipper(ShipperEditModels model, out string message)
        {
            var shipperEntity = _ShipperRepository.GetById(model.ShipperId);

            if (shipperEntity != null)
            {
                var gr = _ShipperRepository.getshipper(model.ShipperId, model.CompanyName, model.Phone);
                if (gr != null)
                {
                    message = Constant.ShipperIsExist;
                    return(false);
                }
                shipperEntity = model.MapToEditEntity(shipperEntity);
                _ShipperRepository.Update(shipperEntity);
                UnitOfwork.SaveChanges();
                message = Constant.UpdateSuccess;
                return(true);
            }
            message = Constant.UpdateFail;
            return(false);
        }
Exemple #19
0
        public bool UpdateOrder(OrderEditModels model, out string message)
        {
            var OrderEntity = _OrderRepository.GetById(model.OrderId);

            if (OrderEntity != null)
            {
                var gr = _OrderRepository.getOrder(model.OrderId, model.CustomerId, model.EmployeeId);
                if (gr != null)
                {
                    message = Constants.OrderIsExist;
                    return(false);
                }
                OrderEntity = model.MapToEditEntity(OrderEntity);
                _OrderRepository.Update(OrderEntity);
                UnitOfwork.SaveChanges();
                message = Constants.UpdateSuccess;
                return(true);
            }
            message = Constants.UpdateFail;
            return(false);
        }
Exemple #20
0
 public bool Delete(int ProductId, out string message)
 {
     try
     {
         var entity = _cartRepository.GetById(ProductId);
         if (entity != null)
         {
             _cartRepository.Delete(ProductId);
             UnitOfwork.SaveChanges();
             message = Constant.DeleteSucces;
             return(true);
         }
         message = Constant.DeleteFail;
         return(false);
     }
     catch
     {
         message = Constant.RecordsisUsedCanNotDeleted;
         return(false);
     }
 }
Exemple #21
0
        public bool UpdateProduct(ProductEditModels model, out string message)
        {
            var ProductEntity = _ProductRepository.GetById(model.ProductId);

            if (ProductEntity != null)
            {
                var gr = _ProductRepository.getProduct(model.ProductId, model.ProductName);
                if (gr != null)
                {
                    message = Constants.ProductIsExist;
                    return(false);
                }
                ProductEntity = model.MapToEditEntity(ProductEntity);
                _ProductRepository.Update(ProductEntity);
                UnitOfwork.SaveChanges();
                message = Constants.UpdateSuccess;
                return(true);
            }
            message = Constants.UpdateFail;
            return(false);
        }
Exemple #22
0
        public bool UpdateEmployee(EmployeeEditModels model, out string message)
        {
            var EmployeeEntity = _EmployeeRepository.GetById(model.EmployeeId);

            if (EmployeeEntity != null)
            {
                var gr = _EmployeeRepository.getEmployee(model.EmployeeId, model.FirstName, model.LastName);
                if (gr != null)
                {
                    message = Constant.EmployeeIsExist;
                    return(false);
                }
                EmployeeEntity = model.MapToEditEntity(EmployeeEntity);
                _EmployeeRepository.Update(EmployeeEntity);
                UnitOfwork.SaveChanges();
                message = Constant.UpdateSuccess;
                return(true);
            }
            message = Constant.UpdateFail;
            return(false);
        }
Exemple #23
0
        public bool UpdateCategory(CategoryEditModels model, out string message)
        {
            var CategoryEntity = _CategoryRepository.GetById(model.CategoryId);

            if (CategoryEntity != null)
            {
                var gr = _CategoryRepository.getCategory(model.CategoryId, model.CategoryName);
                if (gr != null)
                {
                    message = Constant.CategoryIsExist;
                    return(false);
                }
                CategoryEntity = model.MapToEditEntity(CategoryEntity);
                _CategoryRepository.Update(CategoryEntity);
                UnitOfwork.SaveChanges();
                message = Constant.UpdateSuccess;
                return(true);
            }
            message = Constant.UpdateFail;
            return(false);
        }
Exemple #24
0
        public bool UpdateCustomer(CustomerListModels model, out string message)
        {
            var CustomerEntity = _CustomerRepository.GetById(model.CustomerId);

            if (CustomerEntity != null)
            {
                var gr = _CustomerRepository.getCustomer(model.CustomerId, model.ContactName, model.CompanyName);
                if (gr != null)
                {
                    message = Constants.CustomerIsExist;
                    return(false);
                }
                CustomerEntity = model.MapToEntity(CustomerEntity);
                _CustomerRepository.Update(CustomerEntity);
                UnitOfwork.SaveChanges();
                message = Constants.UpdateSuccess;
                return(true);
            }
            message = Constants.UpdateFail;
            return(false);
        }
        public async Task <Profile> Login(string login, string password)
        {
            using (UnitOfwork unitOfWork = _unitOfWorkFactory.CreateUnitOfWork())
            {
                User loginUser = await unitOfWork.UserRepository.GetByUserName(login);

                if (loginUser != null)
                {
                    var passwordHashier = new SaltedHasher(password);
                    if (!SaltedHasher.Verify(loginUser.Salt, loginUser.HashedPassword, password))
                    {
                        return(null);
                    }
                }
                else
                {
                    return(null);
                }

                return(new Profile(loginUser.UserName, loginUser.UserType));
            }
        }
        public async Task <RegistrationResult> Register(string userName, string password, string confirmPassword, string email, UserType userType)
        {
            RegistrationResult result = RegistrationResult.Success;

            if (string.Equals(password, confirmPassword))
            {
                using (UnitOfwork unitOfWork = _unitOfWorkFactory.CreateUnitOfWork())
                {
                    if (await unitOfWork.UserRepository.GetByUserName(userName) != null)
                    {
                        result = RegistrationResult.LoginAlreadyExists;
                    }

                    var passwordHashier = new SaltedHasher(password);

                    User user = new User()
                    {
                        UserName       = userName,
                        HashedPassword = passwordHashier.Hash,
                        Salt           = passwordHashier.Salt,
                        Email          = email,
                        UserType       = userType
                    };


                    if (result == RegistrationResult.Success)
                    {
                        unitOfWork.UserRepository.Create(user);
                        await unitOfWork.SaveAsync();
                    }
                }
            }
            else
            {
                result = RegistrationResult.PasswordDoNotMatch;
            }

            return(result);
        }
        public bool Delete(int OrderDetailId, out string message)
        {
            try
            {
                var entity = _OrderDetailRepository.GetById(OrderDetailId);
                if (entity != null)
                {
                    _OrderDetailRepository.Delete(OrderDetailId);
                    UnitOfwork.SaveChanges();
                    message = Constants.DeleteSuccess;
                    return(true);
                }

                message = Constants.DeleteFail;
                return(false);
            }
            catch
            {
                message = Constants.RecordsisUsedCanNotDeleted;
                return(false);
            }
        }