Example #1
0
        public StockComponent AddStockComponent(StockComponent stockComponent)
        {
            using (var dbContext = new ComputerPartsDBContext())
            {
                StockComponent addedStComponent = dbContext.StockComponents.Add(stockComponent);
                dbContext.SaveChanges();

                return(addedStComponent);
            }
        }
Example #2
0
        public bool AddComponent(Component component)
        {
            using (var dbContext = new ComputerPartsDBContext())
            {
                Component addedComponent = dbContext.Components.Add(component);
                dbContext.SaveChanges();

                return(true);
            }
        }
Example #3
0
        public bool DuplicateComponent(StockComponent component)
        {
            component.Id = new Guid();

            using (var dbContext = new ComputerPartsDBContext())
            {
                StockComponent stockComponent = dbContext.StockComponents.Add(component);
                dbContext.SaveChanges();

                return(true);
            }
        }
        public bool RemoveUser(User user)
        {
            using (var dbContext = new ComputerPartsDBContext())
            {
                var isInDb = dbContext.Users.Any(u => u.Id == user.Id);
                if (isInDb)
                {
                    dbContext.Users.Remove(user);
                    dbContext.SaveChanges();

                    return(true);
                }

                return(false);
            }
        }
        public bool AddUser(User newUser)
        {
            using (var dbContext = new ComputerPartsDBContext())
            {
                var isInDb = dbContext.Users.Any(u => u.Username.ToLower().Equals(newUser.Username.ToLower()));

                if (isInDb)
                {
                    return(false);
                }

                User addedUser = dbContext.Users.Add(newUser);
                dbContext.SaveChanges();

                return(true);
            }
        }
Example #6
0
        public bool RemoveStockComponent(StockComponent stockComponent)
        {
            using (var dbContext = new ComputerPartsDBContext())
            {
                bool isInDb = dbContext.StockComponents.Any(c => c.Id == stockComponent.Id);

                if (isInDb)
                {
                    var remove = dbContext.StockComponents.FirstOrDefault(c => c.Id == stockComponent.Id);

                    dbContext.StockComponents.Remove(remove);

                    dbContext.SaveChanges();

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
        public bool EditUser(User user)
        {
            using (var dbContext = new ComputerPartsDBContext())
            {
                var isInDb = dbContext.Users.Any(u => u.Username.ToLower().Equals(user.Username.ToLower()));

                if (isInDb)
                {
                    var edit = dbContext.Users.FirstOrDefault(u => u.Username.ToLower().Equals(user.Username.ToLower()));

                    edit.Name     = user.Name;
                    edit.Password = user.Password;
                    edit.Role     = user.Role;
                    edit.Surname  = user.Surname;
                    edit.Username = user.Username;

                    dbContext.SaveChanges();
                    return(true);
                }

                return(false);
            }
        }
Example #8
0
        public bool EditStockComponent(StockComponent stockComponent)
        {
            using (var dbContext = new ComputerPartsDBContext())
            {
                var isInDb = dbContext.StockComponents.Any(c => c.Id == stockComponent.Id);
                if (isInDb)
                {
                    var component = dbContext.StockComponents.FirstOrDefault(c => c.Id == stockComponent.Id);
                    component.Count            = stockComponent.Count;
                    component.PhysicalLocation = stockComponent.PhysicalLocation;
                    component.M_Component      = stockComponent.M_Component;
                    component.Type             = stockComponent.Type;

                    dbContext.SaveChanges();

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }