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.º 2
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));
            }
        }
Exemplo n.º 3
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();
     }
 }
Exemplo n.º 4
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.º 5
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 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();
     }
 }
 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.º 8
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;
            }
        }
 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);
     }
 }
Exemplo n.º 10
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.º 12
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());
            }
        }