Exemple #1
0
 public ICollection <Activitie> GetSignerInActivities(User user)
 {
     using (var db = new ActivitiesContext())
     {
         return(db.ActivitiesParticipants.Where(ap => ap.ParticipantLogin == user.Login).Select(ap => ap.Activitie).ToList());
     }
 }
Exemple #2
0
        public Response <User> EditUser(User user, string password, string name)
        {
            using (var db = new ActivitiesContext())
            {
                var editedUser = db.Users.Find(user.Login);

                if (editedUser is null)
                {
                    return(new Response <User>(
                               $"Użutkownik {user.Login} nie istnieje w bazie",
                               true
                               ));
                }

                editedUser.Password = password;
                editedUser.Name     = name;

                db.Users.Add(editedUser);
                db.Entry(editedUser).State = EntityState.Modified;

                db.SaveChanges();

                return(new Response <User>(
                           $"Użytkownik {user.Login} został zedytowany",
                           false
                           ));
            }
        }
Exemple #3
0
 public ParticipantModel(User user)
 {
     using (var db = new ActivitiesContext())
     {
         db.Users.Where(u => u.Login == user.Login).Load();
     }
 }
Exemple #4
0
        public Response <Activitie> CreateActivitie(User user, string name, DateTime startDate, DateTime endDate, int participantsNumber)
        {
            using (var db = new ActivitiesContext())
            {
                var activitiesOverlaping = db.Activities
                                           .Where(a => a.LeaderLogin == user.Login)
                                           .Where(a => !(a.StartDate > endDate || a.EndDate < startDate));

                if (activitiesOverlaping.Count() > 0)
                {
                    return(new Response <Activitie>(
                               $"Posiadasz {activitiesOverlaping.Count()} inne zajęcia w tym terminie",
                               true,
                               activitiesOverlaping.ToList()
                               ));
                }

                db.Activities.Add(new Activitie
                {
                    Name               = name,
                    StartDate          = startDate,
                    EndDate            = endDate,
                    ParticipantsNumber = participantsNumber,
                    LeaderLogin        = user.Login
                });

                db.SaveChanges();

                return(new Response <Activitie>(
                           $"Udało się zmieścić w grafiku twoje nowe zajęcia",
                           false
                           ));
            }
        }
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     using (var db = new ActivitiesContext())
     {
         userDataGrid.ItemsSource = db.ActivitiesParticipants.Where(ap => ap.ActivitieId == activitie.ActivitieId).ToList();
     }
 }
Exemple #6
0
        public Response <Activitie> EditActivitie(Activitie activitie, string name, DateTime startDate, DateTime endDate, int participantsNumber)
        {
            using (var db = new ActivitiesContext())
            {
                var activitiesOverlaping = db.Activities
                                           .Where(a => !(a.StartDate > endDate || a.EndDate < startDate) && a.ActivitieId != activitie.ActivitieId);

                if (activitiesOverlaping.Count() > 0)
                {
                    return(new Response <Activitie>(
                               $"Posiadasz {activitiesOverlaping.Count()} inne zajęcia w tym terminie",
                               true,
                               activitiesOverlaping.ToList()
                               ));
                }

                var editedActivitie = db.Activities.Find(activitie.ActivitieId);

                editedActivitie.Name               = name;
                editedActivitie.StartDate          = startDate;
                editedActivitie.EndDate            = endDate;
                editedActivitie.ParticipantsNumber = participantsNumber;

                db.Activities.Add(editedActivitie);
                db.Entry(editedActivitie).State = EntityState.Modified;

                db.SaveChanges();

                return(new Response <Activitie>(
                           $"Zajęcia zostały zaktualizowane",
                           false
                           ));
            }
        }
Exemple #7
0
        public Response <User> ConfirmUser(string login, string password)
        {
            using (var db = new ActivitiesContext())
            {
                var user = db.Users.Find(login);
                if (user is null)
                {
                    return(new Response <User>(
                               $"Użytkownik o Login {login} nie został znaleziony",
                               true
                               ));
                }

                if (user.Password == password)
                {
                    return(new Response <User>(
                               $"Użytkownik {login} został potwierdzony",
                               false,
                               new List <User>().Append(user).ToList()
                               ));
                }

                return(new Response <User>(
                           "Nieprawidłowe hasło",
                           true
                           ));
            }
        }
Exemple #8
0
        public Response <User> CreateUser(string login, string password, string name, UserType userType)
        {
            using (var db = new ActivitiesContext())
            {
                var users = db.Users.Where(u => u.Login == login);
                if (users.Count() > 0)
                {
                    return(new Response <User>(
                               $"Użytkownik {login} już istenie w bazie",
                               true
                               ));
                }

                db.Users.Add(new User
                {
                    Login    = login,
                    Password = password,
                    Name     = name,
                    Type     = userType
                });
                db.SaveChanges();

                return(new Response <User>(
                           $"Uzytkownik {login} został stworzony",
                           false
                           ));
            }
        }
Exemple #9
0
 public ObservableCollection <Activitie> GetNotSignedInActivities(User user)
 {
     using (var db = new ActivitiesContext())
     {
         db.Activities.Load();
         return(db.Activities.Local);
     }
 }
Exemple #10
0
 private void InitializeFields()
 {
     nameLabel.Content = participant.Name;
     using (var db = new ActivitiesContext())
     {
         detailsLabel.AppendText(db.ParticipantsDescriptions.Where(pd => pd.LeaderLogin == user.Login && pd.ParticipantLogin == participant.Login).FirstOrDefault().Description);
     }
 }
Exemple #11
0
 public ObservableCollection <ActivitieParticipant> GetActivitiesParticipants()
 {
     using (var db = new ActivitiesContext())
     {
         db.ActivitiesParticipants.Load();
         return(db.ActivitiesParticipants.Local);
     }
 }
Exemple #12
0
 public ObservableCollection <Activitie> GetActivities(User user)
 {
     using (var db = new ActivitiesContext())
     {
         db.Activities.Where(a => a.LeaderLogin == user.Login).Load();
         return(db.Activities.Local);
     }
 }
Exemple #13
0
 public ObservableCollection <User> GetUsers()
 {
     using (var db = new ActivitiesContext())
     {
         db.Users.Load();
         return(db.Users.Local);
     }
 }
Exemple #14
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     using (var db = new ActivitiesContext())
     {
         var found = db.ParticipantsDescriptions.Where(pd => pd.LeaderLogin == user.Login && pd.ParticipantLogin == participant.Login).FirstOrDefault();
         found.Description = new TextRange(detailsLabel.Document.ContentStart, detailsLabel.Document.ContentEnd).Text;
         db.SaveChanges();
     }
 }
Exemple #15
0
        public Response <ActivitieParticipant> SignOut(Activitie activitie, User user)
        {
            using (var db = new ActivitiesContext())
            {
                var activitieParticipant = db.ActivitiesParticipants.Where(ap => ap.ActivitieId == activitie.ActivitieId && ap.ParticipantLogin == user.Login).ToList().FirstOrDefault();
                db.ActivitiesParticipants.Remove(activitieParticipant);
                db.SaveChanges();

                return(new Response <ActivitieParticipant>(
                           $"Zostałeś wypisany/na z zajęć",
                           false
                           ));
            }
        }
Exemple #16
0
        public List <ObservableCollection <Activitie> > GetSignedInAndInQueueActivities(User user)
        {
            using (var db = new ActivitiesContext())
            {
                var signed = new ObservableCollection <Activitie>();
                var queue  = new ObservableCollection <Activitie>();

                foreach (var a in db.Users.Find(user.Login).Activities.ToList())
                {
                    var userFound = db.Users.Find(user.Login);

                    if (a.ActivitiesParticipants.OrderByDescending(ap => ap.SignUpDate)
                        .Take(a.ParticipantsNumber).ToList()
                        .Where(ap => ap.ParticipantLogin == user.Login).Count() > 0)
                    {
                        signed.Add(a);
                    }

                    else
                    {
                        queue.Add(a);
                    }

                    /*
                     * var isInQueue = true;
                     *
                     * foreach (var ap in a.ActivitiesParticipants.OrderByDescending(ap => ap.SignUpDate).Take(a.ParticipantsNumber).ToList())
                     *  if (ap.User == user)
                     *  {
                     *      signed.Add(a);
                     *      isInQueue = false;
                     *      break;
                     *  }
                     *
                     * if (isInQueue)
                     *  queue.Add(a);
                     *
                     */
                }
                var list = new List <ObservableCollection <Activitie> >();
                list.Add(signed);
                list.Add(queue);
                return(list);
            }
        }
Exemple #17
0
        private void InitializeFields()
        {
            using (var db = new ActivitiesContext())
            {
                var details = db.Activities.Find(activitie.ActivitieId);

                NameLabel.Content               = details.Name;
                StartDateLabel.Content          = details.StartDate.ToString();
                EndDateLabel.Content            = details.EndDate.ToString();
                ParticipansNumbertLabel.Content = details.ParticipantsNumber.ToString();

                /*
                 * if (details.ActivitiesParticipants.OrderByDescending(ap => ap.SignUpDate).Take(details.ParticipantsNumber))
                 * {
                 *
                 * }
                 */
            }
        }
Exemple #18
0
        public Response <ActivitieParticipant> SignIn(Activitie activitie, User user)
        {
            using (var db = new ActivitiesContext())
            {
                db.ActivitiesParticipants.Add(new ActivitieParticipant
                {
                    ActivitieId      = activitie.ActivitieId,
                    ParticipantLogin = user.Login,
                    SignUpDate       = DateTime.Now
                });

                db.SaveChanges();

                return(new Response <ActivitieParticipant>(
                           $"Zostałeś zapisany na zajęcia",
                           false
                           ));
            }
        }
Exemple #19
0
        public StartModel()
        {
            using (var db = new ActivitiesContext())
            {
                db.Users.Where(u => u.Type == UserType.Admin).Load();

                if (db.Users.ToList().Count() == 0)
                {
                    db.Users.Add(new User
                    {
                        Login    = "******",
                        Password = "******",
                        Name     = "root",
                        Type     = UserType.Admin
                    });

                    db.SaveChanges();
                }
            }
        }
Exemple #20
0
        public Response <Activitie> DeleteActivitie(Activitie activitie)
        {
            using (var db = new ActivitiesContext())
            {
                var found = db.Activities.Find(activitie.ActivitieId);
                if (found is null)
                {
                    return(new Response <Activitie>(
                               $"Nie ma takich zajęć w bazie",
                               true
                               ));
                }

                db.Activities.Remove(found);
                db.SaveChanges();

                return(new Response <Activitie>(
                           $"Zajęcia {activitie.Name} został usunięte",
                           false
                           ));
            }
        }
Exemple #21
0
        public Response <User> DeleteUser(string login)
        {
            using (var db = new ActivitiesContext())
            {
                var user = db.Users.Find(login);

                if (user is null)
                {
                    return(new Response <User>(
                               $"Nie ma takiego użytkownika jak {login}",
                               true
                               ));
                }

                db.Users.Remove(user);
                db.SaveChanges();

                return(new Response <User>(
                           $"Użytkownik {login} został usunięty",
                           false
                           ));
            }
        }
 public ActivitiesController(ActivitiesContext context)
 {
     _context = context;
 }
 public DbActivityRepository(ActivitiesContext dbCtx)
 {
     _dbCtx = dbCtx;
 }
Exemple #24
0
 public ActivityRepository(ActivitiesContext dbContext)
 {
     _dbContext = dbContext;
 }