} // End GetById

        public ActiveToken Create(ActiveToken activeToken, string userName, string currentToken, string SourceIdentifier)
        {
            // Validation
            if (string.IsNullOrWhiteSpace(userName))
            {
                throw new ApplicationException("The username for the current active token can not be null or empty");
            }
            if (string.IsNullOrWhiteSpace(currentToken))
            {
                throw new ApplicationException("The current token  can not be null or empty");
            }

            //if (_context.Users.Any(x => x.Username == user.Username))
            //    throw new AppException("Username \"" + user.Username + "\" is already taken");

            //byte[] passwordHash, passwordSalt;
            //CreatePasswordHash(password, out passwordHash, out passwordSalt);

            activeToken.UserName         = userName;
            activeToken.CurrentToken     = currentToken;
            activeToken.Status           = true;
            activeToken.TokenDate        = DateTime.Now;
            activeToken.SourceIdentifier = SourceIdentifier;
            // Hardcoded by now.... TODO: Fix this hardcoded value
            activeToken.TokenExpireDate = DateTime.Now.AddHours(24);

            _context.ActiveTokens.Add(activeToken);
            _context.SaveChanges();

            return(activeToken);
        } // End Create
Exemple #2
0
        } // End GetById

        public Role Create(Role role, string roleName)
        {
            // Validation
            if (string.IsNullOrWhiteSpace(roleName))
            {
                throw new System.ApplicationException("The role name can not be null or empty");
            }

            role.RoleName = roleName;

            _context.Roles.Add(role);
            _context.SaveChanges();

            return(role);
        } // End Create
Exemple #3
0
        public bool ClearDatabase()
        {
            var cleared       = _context.Database.EnsureDeleted();
            var created       = _context.Database.EnsureCreated();
            var entitiesadded = _context.SaveChanges();

            return(cleared && created && entitiesadded == 0);
        }
Exemple #4
0
        } // End GetById

        public void Delete(int id)
        {
            var user = _context.Users.Find(id);

            if (user != null)
            {
                _context.Users.Remove(user);
                _context.SaveChanges();
            }
        } // End Delete
Exemple #5
0
        } // End GetById

        public void Delete(int id)
        {
            var stockMovementType = _context.StockMovementTypes.Find(id);

            if (stockMovementType != null)
            {
                _context.StockMovementTypes.Remove(stockMovementType);
                _context.SaveChanges();
            }
        } // End Delete
Exemple #6
0
        } // End GetById

        public void Delete(int id)
        {
            var auditLogPurchase = _context.AuditLogPurchases.Find(id);

            if (auditLogPurchase != null)
            {
                _context.AuditLogPurchases.Remove(auditLogPurchase);
                _context.SaveChanges();
            }
        } // End Delete
Exemple #7
0
        } // End GetById

        public User Create(User user, string password)
        {
            // Validation
            if (string.IsNullOrWhiteSpace(password))
            {
                throw new System.ApplicationException("Password is required to perfom this action");
            }

            if (_context.Users.Any(x => x.Username == user.Username))
            {
                throw new System.ApplicationException("Username \"" + user.Username + "\" is already taken");
            }

            byte[] passwordHash, passwordSalt;
            CreatePasswordHash(password, out passwordHash, out passwordSalt);

            user.PasswordHash = passwordHash;
            user.PasswordSalt = passwordSalt;

            _context.Users.Add(user);
            _context.SaveChanges();

            return(user);
        } // End Create
Exemple #8
0
        } // End GetById

        public Product Delete(int id, User user)
        {
            RoleService rService = new RoleService(_context);
            Role        role     = new Role();

            role = rService.GetById(user.Role.Id);

            Product returnProduct = new Product();
            var     product       = _context.Products.Find(id);

            if (role.RoleName == "Admin")
            {
                if (product != null)
                {
                    _context.Products.Remove(product);
                    _context.SaveChanges();

                    returnProduct.Description = "Delete product Successfully";
                    returnProduct.Status      = false;
                    returnProduct.Id          = 0;
                    returnProduct.Price       = 0;
                    return(returnProduct);
                }
                else
                {
                    returnProduct.Description = "The product doesn't exists!";
                    returnProduct.Status      = false;
                    returnProduct.Id          = 0;
                    returnProduct.Price       = 0;
                    return(returnProduct);
                }
            }
            else
            {
                returnProduct.Description = "Only Admin users can delete products!";
                returnProduct.Status      = false;
                returnProduct.Id          = 0;
                returnProduct.Price       = 0;
                return(returnProduct);
            }
        } // End Delete