Exemple #1
0
        /// <summary>
        /// Create Login Account
        /// </summary>
        /// <param name="login"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public async Task <Login> Create(LoginViewModel login, int userId)
        {
            // validation
            if (string.IsNullOrWhiteSpace(login.Password))
            {
                throw new AppException("Password is required");
            }

            if (await _repositoryContext.Login.AnyAsync(x => x.Username == login.Username))
            {
                throw new AppException("Email \"" + login.Username + "\" is already taken");
            }

            CreatePasswordHash(login.Password, out var passwordHash, out var passwordSalt);

            var loginToCreate = new Login
            {
                Username     = login.Username,
                UserID       = userId,
                PasswordHash = passwordHash,
                PasswordSalt = passwordSalt,
                Status       = true
            };

            _repositoryContext.Login.Add(loginToCreate);
            _repositoryContext.SaveChanges();

            return(loginToCreate);
        }
Exemple #2
0
        public async Task Update(Customer customerParam, int BusinessID)
        {
            var customer = await _repositoryContext.Customer.SingleAsync(x => x.ID == customerParam.ID && x.Business.ID == BusinessID);

            if (customer.ToString() == null)
            {
                throw new AppException("Customer Account not found");
            }

            if (customerParam.Phone != customer.Phone)
            {
                // username has changed so check if the new username is already taken
                if (_repositoryContext.Customer.Where(p => p.Business.ID == BusinessID).Any(x => x.Phone == customerParam.Phone))
                {
                    throw new AppException("Customer Phone " + customerParam.Phone + " is already taken");
                }
            }

            customer.Title    = customerParam.Title;
            customer.Name     = customerParam.Name;
            customer.Address  = customerParam.Address;
            customer.Email    = customerParam.Email;
            customer.Phone    = customerParam.Phone;
            customer.Platform = customerParam.Platform;

            _repositoryContext.Customer.Update(customer);
            _repositoryContext.SaveChanges();
        }
        public new async Task Update(User userParam)
        {
            var user = await _repositoryContext.User.FindAsync(userParam.ID);

            if (user == null)
            {
                throw new AppException("User Account not found");
            }

            if (userParam.Email != user.Email)
            {
                // Email has changed so check if the new Email is already taken
                if (await _repositoryContext.User.AnyAsync(x => x.Email == userParam.Email))
                {
                    throw new AppException("Email " + userParam.Email + " is already taken");
                }
            }

            user.Lastname  = userParam.Lastname;
            user.Firstname = userParam.Firstname;
            user.Gender    = userParam.Gender;
            user.Birthdate = userParam.Birthdate;
            user.Email     = userParam.Email;

            _repositoryContext.User.Update(user);
            _repositoryContext.SaveChanges();
        }
        public new async Task <Business> Create(BusinessViewModel business, int UserID)
        {
            //if (await _repositoryContext.Business.AnyAsync(x => x.Name == business.Name || x.Email == business.Email || x.Phone == business.Phone))
            //    throw new AppException("Business Name \"" + business.Name + " or Business Phone \"" + business.Phone + "or Business Email" + business.Email + "\" is already taken");

            var businessTocreate = new Business
            {
                Name        = business.Name,
                Description = business.Description,
                Email       = business.Email,
                Industry    = business.Industry,
                Phone       = business.Phone,
                UserID      = UserID
            };

            _repositoryContext.Business.Add(businessTocreate);
            _repositoryContext.SaveChanges();

            return(businessTocreate);
        }
        public async Task <Transaction> Create(Transaction transaction, int BusinessID)
        {
            if (_repositoryContext.Transaction.Any(x => x.BusinessID == BusinessID && x.ID == transaction.ID))
            {
                throw new AppException("Transaction With ID\"" + transaction.ID + "\" Found in Database");
            }


            _repositoryContext.Transaction.Add(transaction);
            _repositoryContext.SaveChanges();

            return(transaction);
        }
Exemple #6
0
        public async Task <Delivery> Create(Delivery delivery, int BusinessID, int OrderID)
        {
            if (_repositoryContext.Delivery.Any(x => x.BusinessID == BusinessID && x.Order.ID == OrderID))
            {
                throw new AppException("Delivery With Invoice Number\"" + delivery.Order.InvoiceNumber + "\" Found in Database");
            }


            _repositoryContext.Delivery.Add(delivery);
            _repositoryContext.SaveChanges();

            return(delivery);
        }
Exemple #7
0
        public async Task <Order> Create(OrderViewModel order, int BusinessID)
        {
            if (_repositoryContext.Order.Any(x => x.BusinessID == BusinessID && x.InvoiceNumber == order.InvoiceNumber))
            {
                throw new AppException("Order With Invoice Number\"" + order.InvoiceNumber + "\" Found in Database");
            }
            var orderToCreate = new Order
            {
                BusinessID    = BusinessID,
                InvoiceNumber = order.InvoiceNumber,
                CustomerID    = order.CustomerID,
                Description   = order.Description,
                Date          = order.Date,
                Discount      = order.Discount,
                OrderPlatform = order.OrderPlatform,
                Status        = order.Status
            };

            _repositoryContext.Order.Add(orderToCreate);
            _repositoryContext.SaveChanges();

            return(orderToCreate);
        }
Exemple #8
0
 public void Save()
 {
     _repoContext.SaveChanges();
 }