public static List <NotesModel> GetNotesId(int id, int Userid)
 {
     using (var dbContext = new FiszkiContext())
     {
         return(dbContext.NotesTable.Where(item => item.id == id && item.userId == Userid).ToList());
     }
 }
        public static string Login(UserAuthDTO value)
        {
            using (var dbContext = new FiszkiContext())
            {
                var user = dbContext.Users.FirstOrDefault(x => x.Login == value.Login);
                if (user == null)
                {
                    return(null);
                }

                if (user.Password != value.Password)
                {
                    dbContext.UsersLogs.Add(new Repositories.UserLogs
                    {
                        UserId      = user.Id,
                        LoginDate   = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                        LoginStatus = "Nieprawidłowe hasło"
                    });
                    dbContext.SaveChanges();

                    return(null);
                }

                dbContext.UsersLogs.Add(new Repositories.UserLogs
                {
                    UserId      = user.Id,
                    LoginDate   = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                    LoginStatus = "Zalogowano"
                });
                dbContext.SaveChanges();

                return(JWTService.GenerateToken(user.Id));
            }
        }
Exemplo n.º 3
0
 public static List <Progress> GetProgressId(int userId, int id)
 {
     using (var dbContext = new FiszkiContext())
     {
         return(dbContext.ProgressTable.Where(p => p.UserId == userId && p.WordId == id).ToList());
     }
 }
 public static List <UserLogs> GetUserLogsList(int idUser)
 {
     using (var dbContext = new FiszkiContext())
     {
         return(dbContext.UsersLogs.Where(p => p.UserId == idUser).ToList());
     }
 }
Exemplo n.º 5
0
        public static string Login(CredentialsModel value)
        {
            using (var dbContext = new FiszkiContext())
            {
                var user = dbContext.Users.FirstOrDefault(x => x.Login == value.Login);
                if (user == null)
                {
                    return(null);
                }

                if (user.Password != value.Password)
                {
                    dbContext.UsersLogs.Add(new Repositories.UserLogs   //Dodanie informacji o logowaniu + złe hasło
                    {
                        UserId      = user.Id,
                        LoginDate   = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), // Data rejestracji
                        LoginStatus = "Nieprawidłowe hasło"
                                                                                    //var x = UserLogsRepository.AddUserLogsList(user.Id, )
                    });
                    dbContext.SaveChanges();

                    return(null);
                }

                dbContext.UsersLogs.Add(new Repositories.UserLogs   //Dodanie informacji o logowaniu + złe hasło
                {
                    UserId      = user.Id,
                    LoginDate   = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), // Data rejestracji
                    LoginStatus = "Zalogowano"
                });
                dbContext.SaveChanges();

                return(JWTService.GenerateToken(user.Id));
            }
        }
        public static (string login, string dateAdd) Account(string id)
        {
            var dbContext = new FiszkiContext();;
            var login     = dbContext.Users.FirstOrDefault(item => item.Id.ToString() == id).Login;
            var dateAdd   = dbContext.Users.FirstOrDefault(item => item.Id.ToString() == id).DateAdd;

            return(login, dateAdd);
        }
Exemplo n.º 7
0
 public static List <UserLogs> GetUserLogsList(int idUser) // Lista z repozytorium, ponieważ będziemy zwracać (...VievModel)
 {
     //return Tascs.GetAllTasc();
     using (var dbContext = new FiszkiContext())       // Tutaj dodanemy new context stworzony w osobnym pliku
     {
         return(dbContext.UsersLogs.Where(p => p.UserId == idUser).ToList());
     }
 }
Exemplo n.º 8
0
 public static void DeleteWord(int id)
 {
     using (var dbContext = new FiszkiContext())
     {
         var item = dbContext.WordsTable.FirstOrDefault(x => x.Id == id);
         dbContext.WordsTable.Remove(item);
         dbContext.SaveChanges();
     }
 }
 public static List <NotesModel> Get(string itemType, int userId)
 {
     using (var dbContext = new FiszkiContext())
         if (String.IsNullOrEmpty(itemType))
         {
             return(dbContext.NotesTable.Where(item => item.userId == userId).ToList());
         }
         else
         {
             return(dbContext.NotesTable.Where(item => item.type == itemType && item.userId == userId).ToList());
         }
 }
 public static void AddUserLogsList(int id, string LoginEvent)
 {
     using (var dbContext = new FiszkiContext())
     {
         dbContext.UsersLogs.Add(new Repositories.UserLogs
         {
             UserId      = id,
             LoginDate   = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
             LoginStatus = "Nieprawidłowe hasło"
         });
         dbContext.SaveChanges();
     }
 }
Exemplo n.º 11
0
 public static void AddUserLogsList(int id, string LoginEvent)
 {
     using (var dbContext = new FiszkiContext())           //standardowa linijka
     {
         dbContext.UsersLogs.Add(new Repositories.UserLogs //Dodanie informacji o logowaniu + złe hasło
         {
             UserId      = id,
             LoginDate   = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), // Data rejestracji
             LoginStatus = "Nieprawidłowe hasło"
         });
         dbContext.SaveChanges();
     }
 }
Exemplo n.º 12
0
        public static void EditWord(int id, Words value)
        {
            using (var dbContext = new FiszkiContext())
            {
                var Word = dbContext.WordsTable.FirstOrDefault(x => x.Id == id);

                Word.Wordpl       = value.Wordpl;
                Word.Worden       = value.Worden;
                Word.WordCategory = value.WordCategory;

                dbContext.SaveChanges();
            }
        }
 public static int DeleteNote(int id, int Userid)
 {
     using (var dbContext = new FiszkiContext())
     {
         var note = dbContext.NotesTable.FirstOrDefault(x => x.id == id && x.userId == Userid);
         if (note == null)
         {
             return(0);
         }
         dbContext.NotesTable.Remove(note);
         dbContext.SaveChanges();
         return(id);
     }
 }
Exemplo n.º 14
0
        public static void AddWord(Words value)
        {
            using (var dbContext = new FiszkiContext())
            {
                var newWord = new Words
                {
                    Wordpl       = value.Wordpl,
                    Worden       = value.Worden,
                    WordCategory = value.WordCategory
                };
                dbContext.WordsTable.Add(newWord);
                dbContext.SaveChanges();

                int id = newWord.Id;
            }
        }
Exemplo n.º 15
0
        // === Dla poniższych metod ===
        public static List <WordDTO> WordsWithUserProgress(int id)
        {
            using (var dbContext = new FiszkiContext())
            {
                List <Words>    words    = dbContext.WordsTable.ToList();
                List <Progress> progress = dbContext.ProgressTable.Where(item => item.UserId == id).ToList();

                List <WordDTO> WordsWithProgress = (from w in words
                                                    join p in progress
                                                    on w.Id equals p.WordId
                                                    into subProgress
                                                    from userProgress in subProgress.DefaultIfEmpty()
                                                    select new WordDTO {
                    Id = w.Id, Wordpl = w.Wordpl, Worden = w.Worden, WordCategory = w.WordCategory, WordStatus = userProgress?.WordStatus ?? null, DateEdit = userProgress?.DateEdit ?? null
                }).ToList();
                return(WordsWithProgress);
            }
        }
 public static List <NotesModel> EditNote(int id, NotesModel Note, int Userid)
 {
     using (var dbContext = new FiszkiContext())
     {
         var editedNote = dbContext.NotesTable.FirstOrDefault(x => x.id == id && x.userId == Userid);
         {
             editedNote.type        = Note.type;
             editedNote.title       = Note.title;
             editedNote.articleUrl  = Note.articleUrl;
             editedNote.noteContent = Note.noteContent;
             editedNote.dateUser    = Note.dateUser;
             editedNote.lastEdit    = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
             editedNote.rating      = Note.rating;
             editedNote.isActive    = 1;
         };
         dbContext.SaveChanges();
         var EditetItem = dbContext.NotesTable.Where(item => item.id == id).ToList();
         return(EditetItem);
     }
 }
        public static StatisticDTO GetStatistic(int id)
        {
            using (var dbContext = new FiszkiContext())
            {
                var userProgress = dbContext.ProgressTable.Where(item => item.UserId == id);

                var GETallWords    = dbContext.WordsTable.Count();
                var GETwiem        = userProgress.Where(item => item.WordStatus == "W" && item.UserId == id).Count();
                var GETmniej       = userProgress.Where(item => item.WordStatus == "M" && item.UserId == id).Count();
                var GETnie         = userProgress.Where(item => item.WordStatus == "N" && item.UserId == id).Count();
                var GETallProgress = userProgress.Where(item => item.UserId == id).Count();
                var GETtoday       = userProgress.Where(item => item.DateEdit.Contains(DateTime.Now.ToString("yyyy-MM-dd"))).Count();
                var GETp_1         = userProgress.Where(item => item.DateEdit.Contains(DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"))).Count();
                var GETp_2         = userProgress.Where(item => item.DateEdit.Contains(DateTime.Now.AddDays(-2).ToString("yyyy-MM-dd"))).Count();
                var GETp_3         = userProgress.Where(item => item.DateEdit.Contains(DateTime.Now.AddDays(-3).ToString("yyyy-MM-dd"))).Count();
                var GETp_4         = userProgress.Where(item => item.DateEdit.Contains(DateTime.Now.AddDays(-4).ToString("yyyy-MM-dd"))).Count();
                var GETp_5         = userProgress.Where(item => item.DateEdit.Contains(DateTime.Now.AddDays(-5).ToString("yyyy-MM-dd"))).Count();
                var GETp_6         = userProgress.Where(item => item.DateEdit.Contains(DateTime.Now.AddDays(-6).ToString("yyyy-MM-dd"))).Count();
                var GETp_7         = userProgress.Where(item => item.DateEdit.Contains(DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd"))).Count();

                StatisticDTO result = new StatisticDTO
                {
                    allWords    = GETallWords,
                    wiem        = GETwiem,
                    mniej       = GETmniej,
                    nie         = GETnie,
                    allProgress = GETallProgress,
                    today       = GETtoday,
                    p_1         = GETp_1,
                    p_2         = GETp_2,
                    p_3         = GETp_3,
                    p_4         = GETp_4,
                    p_5         = GETp_5,
                    p_6         = GETp_6,
                    p_7         = GETp_7
                };

                return(result);
            }
        }
Exemplo n.º 18
0
        public static (string status, string coment, string token) Register(CredentialsModel value)
        {
            using (var dbContext = new FiszkiContext())
            {
                var user = dbContext.Users.FirstOrDefault(x => x.Login == value.Login);
                if (user != null)
                {
                    return(null, "Login zajęty", null);
                }

                if (value.Login.Length < 4)
                {
                    return(null, "Login musi mieć minimum 5 znaków", null);
                }

                if (value.Password.Length < 4)
                {
                    return(null, "Hasło musi mieć minimum 5 znaków", null);
                }

                if (value.Login == value.Password)
                {
                    return(null, "Login musi się różnic od hasła", null);
                }

                var newAccount = new User
                {
                    Login    = value.Login,
                    Password = value.Password,
                    DateAdd  = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // Data rejestracji
                };

                dbContext.Users.Add(newAccount);
                dbContext.SaveChanges();

                int newAccountId = newAccount.Id;
                //return ("ok", $"{value.Login} [{newAccountId}], konto zostało dodane, możesz się zalogować");
                return("ok", null, JWTService.GenerateToken(newAccountId));
            }
        }
        public static (string status, string coment, string token) Register(UserAuthDTO value)
        {
            using (var dbContext = new FiszkiContext())
            {
                var user = dbContext.Users.FirstOrDefault(x => x.Login == value.Login);
                if (user != null)
                {
                    return(null, "Login zajęty", null);
                }

                if (value.Login.Length < 4)
                {
                    return(null, "Login musi mieć minimum 5 znaków", null);
                }

                if (value.Password.Length < 4)
                {
                    return(null, "Hasło musi mieć minimum 5 znaków", null);
                }

                if (value.Login == value.Password)
                {
                    return(null, "Login musi się różnic od hasła", null);
                }

                var newAccount = new User
                {
                    Login    = value.Login,
                    Password = value.Password,
                    DateAdd  = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
                };

                dbContext.Users.Add(newAccount);
                dbContext.SaveChanges();

                int newAccountId = newAccount.Id;
                return("ok", null, JWTService.GenerateToken(newAccountId));
            }
        }
Exemplo n.º 20
0
 public static void AddProgress(Progress progresUpdate, int userId)
 {
     using (var dbContext = new FiszkiContext())
     {
         var userProgres = dbContext.ProgressTable.FirstOrDefault(x => x.UserId == userId && x.WordId == progresUpdate.WordId);
         if (userProgres != null)
         {
             userProgres.WordStatus = progresUpdate.WordStatus;
         }
         else
         {
             var newProgress = new Progress
             {
                 UserId     = userId,
                 WordId     = progresUpdate.WordId,
                 WordStatus = progresUpdate.WordStatus,
                 DateEdit   = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
             };
             dbContext.ProgressTable.Add(newProgress);
         }
         dbContext.SaveChanges();
     }
 }
        public static List <NotesModel> AddNote(NotesModel NewNote, int Userid)
        {
            using (var dbContext = new FiszkiContext())
            {
                var newNote = new NotesModel
                {
                    userId      = Userid,
                    type        = NewNote.type,
                    title       = NewNote.title,
                    articleUrl  = NewNote.articleUrl,
                    noteContent = NewNote.noteContent,
                    dateUser    = NewNote.dateUser,
                    created     = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                    lastEdit    = null,
                    rating      = NewNote.rating,
                    isActive    = 1,
                };
                dbContext.NotesTable.Add(newNote);
                dbContext.SaveChanges();

                int id = newNote.id;
                return(dbContext.NotesTable.Where(item => item.id == id).ToList());
            }
        }