public IActionResult Post(string name, string author)
 {
     try
     {
         Regex reg = new Regex(@"[A-ZА-Я0-9]?[a-zа-я0-9]+ ?[A-ZА-Я0-9]?[a-zа-я0-9]*");
         if (reg.IsMatch(author) == true)
         {
             List <TrackListModel> tracks = _db.Get <TrackListModel>().ToList().Values.ToList();
             TrackListModel        check  = tracks.FirstOrDefault(u => u.Author == author);
             if (check.Name == "....." && check != null)
             {
                 _db.Remove <TrackListModel>(check.Id);
             }
             TrackListModel track = new TrackListModel()
             {
                 Name = name, Author = author
             };
             _db.Insert <TrackListModel>(track);
             return(View("TrackList"));
         }
         else
         {
             return(ServerError());
         }
     }
     catch
     {
         Console.WriteLine("Invalid input");
         return(ServerError());
     }
 }
        public async Task <IActionResult> Register(RegisterModel model)
        {
            if (ModelBindingState.IsAllSet)
            {
                List <User> users = new List <User>();
                var         query = _db.Get <User>();
                foreach (var e in query.ToList())
                {
                    users.Add(e.Value);
                }

                User user = users.FirstOrDefault(u => u.Email == model.Email);
                if (user == null)
                {
                    User reg = new User()
                    {
                        Email = model.Email, Name = model.Name, Surname = model.Surname, Password = model.GetPasswordHash()
                    };
                    _db.Insert <User>(reg);
                    await Authenticate(model.Email);

                    return(Redirect(Url("~/Account/Profile")));
                }
            }

            return(Redirect(Url("~/Account/Login")));
        }
Beispiel #3
0
        public IActionResult CreateTopic(string name, string content)
        {
            string token = Context.Session.GetString("AuthToken");

            if (token == null)
            {
                Redirect(Url("~/Account/Login"));
            }
            var         uquery = _db.Get <User>();
            List <User> users  = uquery.Where(u => u.Email == token).ToList().Values.ToList();

            if (users.Count == 0)
            {
                return(Status(404));
            }

            if (users.Count > 1)
            {
                return(ServerError());
            }
            var userName = users[0].Name + " " + users[0].Surname;
            var dict     = new Dictionary <string, string>();

            dict.Add(userName, content);
            var forum = new Forum()
            {
                Id      = _db.Get <Forum>().ToList().Count() + 1,
                Content = dict,
                Name    = name
            };

            _db.Insert <Forum>(forum);
            return(Redirect(Url("~/Forum")));
        }
 public IActionResult Post(Tournament tournament)
 {
     try
     {
         Regex reg = new Regex(@"\d\d\.\d\d\.\d\d");
         if (!(reg.IsMatch(tournament.Date)))
         {
             return(ServerError());
         }
         _db.Insert <Tournament>(tournament);
         return(View("Tournaments")); //return List<Tournament>
     }
     catch
     {
         Console.WriteLine("Invalid input");
         return(ServerError());
     }
 }
Beispiel #5
0
 public IActionResult Post(Record record)
 {
     /*if (json == null)
      *  return ServerError();
      * Record record = JsonSerializer.Deserialize<Record>(json);*/
     try
     {
         Regex reg = new Regex(@"[A-ZА-Я]?[a-zа-я]+");
         if (reg.IsMatch(record.Author) == true)
         {
             _db.Insert <Record>(record);
         }
         else
         {
             return(ServerError());
         }
         return(View("Records"));
     }
     catch
     {
         Console.WriteLine("Invalid input");
         return(ServerError());
     }
 }