Пример #1
0
        public void Add(OrderModel order)
        {
            Guard.WhenArgument(order, "order").IsNull().Throw();

            var mapped = mapper.Map <OrderModel, Order>(order);

            this.orders.Add(mapped);
            unitOfWork.SaveChanges();
        }
Пример #2
0
        public void AddNewAddress(string addressText, int userId)
        {
            Guard.WhenArgument(addressText, "addressText").IsNull().Throw();
            var user = this.userService.GetSpecificUser(userId);

            AddressModel addressDTO = new AddressModel()
            {
                AddressText = addressText,
                UserId      = userId
            };

            this.addresses.Add(this.mapper.Map <AddressModel, Address>(addressDTO));
            unitOfWork.SaveChanges();
        }
Пример #3
0
        public void AddNewBankCard(string number, DateTime expDate, string holderName, int userId)
        {
            Guard.WhenArgument(number, "number").IsNull().Throw();
            Guard.WhenArgument(holderName, "holderName").IsNull().Throw();

            BankCardModel bankCardDTO = new BankCardModel()
            {
                Number         = number,
                ExpirationDate = expDate,
                Name           = holderName,
                UserId         = userId
            };

            this.bankCards.Add(this.mapper.Map <BankCardModel, BankCard>(bankCardDTO));
            unitOfWork.SaveChanges();
        }
Пример #4
0
        public bool RegisterUser
            (string userName, string password, string phoneNumber,
            string firstName      = null,
            string lastName       = null,
            string address        = null,
            string bankCardNumber = null,
            DateTime?expDate      = null,
            string cardName       = null)
        {
            Guard.WhenArgument(userName, "userName").IsNullOrEmpty().Throw();
            Guard.WhenArgument(password, "password").IsNullOrEmpty().Throw();
            Guard.WhenArgument(phoneNumber, "phoneNumber").IsNullOrEmpty().Throw();
            try
            {
                var hashedPassword = hashing.GetSHA1HashData(password);

                var userModel = new UserModel()
                {
                    Username    = userName,
                    Password    = hashedPassword,
                    PhoneNumber = phoneNumber,
                    FirstName   = firstName,
                    LastName    = lastName,
                };

                var userToAdd = this.mapper.Map <UserModel, User>(userModel);
                var user      = this.GetSpecificUser(userModel.Username);

                if (address != string.Empty && address != string.Empty)
                {
                    var a = new AddressModel()
                    {
                        AddressText = address
                    };
                    var addressToAdd = this.mapper.Map <AddressModel, Address>(a);
                    userToAdd.Adresses.Add(addressToAdd);
                }

                if (bankCardNumber != string.Empty && expDate != null && cardName != string.Empty && bankCardNumber != null && expDate != null && cardName != null)
                {
                    var c = new BankCardModel()
                    {
                        Number         = bankCardNumber,
                        ExpirationDate = expDate,
                        Name           = cardName,
                        User           = userToAdd
                    };

                    var cardToAdd = this.mapper.Map <BankCardModel, BankCard>(c);
                    userToAdd.BankCards.Add(cardToAdd);
                }

                this.users.Add(userToAdd);
                unitOfWork.SaveChanges();
                return(true);
            }
            catch (System.Exception)
            {
                return(false);
            }
        }
Пример #5
0
 public void AddProducts(ICollection <Product> products)
 {
     Guard.WhenArgument(products, "products").IsNull().Throw();
     this.products.Add(products);
     unitOfWork.SaveChanges();
 }
Пример #6
0
 public IRepositoryAsync <SongEntity, Guid> RepositoryAsync()
 {
     _context.SaveChanges();
     return(_context.RepositoryAsync <SongEntity, Guid>());
 }