public User FindUser(string username)
 {
     using (var dbContext = new ComputerPartsDBContext())
     {
         return(dbContext.Users.FirstOrDefault(u => u.Username.ToLower().Equals(username.ToLower())));
     }
 }
Пример #2
0
 public IEnumerable <Component> GetComponents()
 {
     using (var dbContext = new ComputerPartsDBContext())
     {
         return(dbContext.Components.ToList());
     }
 }
Пример #3
0
        public StockComponent AddStockComponent(StockComponent stockComponent)
        {
            using (var dbContext = new ComputerPartsDBContext())
            {
                StockComponent addedStComponent = dbContext.StockComponents.Add(stockComponent);
                dbContext.SaveChanges();

                return(addedStComponent);
            }
        }
Пример #4
0
        public bool AddComponent(Component component)
        {
            using (var dbContext = new ComputerPartsDBContext())
            {
                Component addedComponent = dbContext.Components.Add(component);
                dbContext.SaveChanges();

                return(true);
            }
        }
Пример #5
0
 public IEnumerable <StockComponent> GetStockComponents()
 {
     using (var dbContext = new ComputerPartsDBContext())
     {
         var components = dbContext.StockComponents
                          .Include(component => component.M_Component)
                          .ToList();
         return(components);
     }
 }
Пример #6
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);
            }
        }
Пример #7
0
 public StockComponent GetStockComponent(Guid id)
 {
     using (var dbContext = new ComputerPartsDBContext())
     {
         var isInDb = dbContext.StockComponents.Any(c => c.Id == id);
         if (isInDb)
         {
             return(dbContext.StockComponents.Include(component => component.M_Component).FirstOrDefault(c => c.Id == id));
         }
         else
         {
             return(null);
         }
     }
 }
        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);
            }
        }
Пример #10
0
        public bool EditComponent(Component component)
        {
            using (var dbContext = new ComputerPartsDBContext())
            {
                bool isInDb = dbContext.Components.Any(c => c.Id == component.Id);

                if (isInDb)
                {
                    var edit = dbContext.Components.FirstOrDefault(c => c.Id == component.Id);

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Пример #11
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);
            }
        }
Пример #13
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);
                }
            }
        }