Esempio n. 1
0
 public ActionResult Registration(Users model)
 {
     if (string.IsNullOrEmpty(model.Name))
     {
         ModelState.AddModelError("Name", "The Name field is required.");
     }
     if (ModelState.IsValid)
     {
         using (var db = new SeriesEntities())
         {
             var queryUser = db.Users.FirstOrDefault(u => u.Email == model.Email);
             if (queryUser == null)
             {
                 var encryptedPassword = CustomEnrypt.Encrypt(model.Password);
                 var user = db.Users.Create();
                 user.Email    = model.Email;
                 user.Password = encryptedPassword;
                 user.Name     = model.Name;
                 db.Users.Add(user);
                 db.SaveChanges();
             }
             else
             {
                 return(RedirectToAction("Registration"));
             }
         }
     }
     else
     {
         ModelState.AddModelError("", "One or more fields have been");
     }
     return(View());
 }
Esempio n. 2
0
        public ActionResult Index(Series list, string Seen)
        {
            if (ModelState.IsValid)
            {
                List <int> userId = db.Users.Where(u => u.Email == sessionEmail.Value).Select(u => u.ID).ToList();
                string     name   = Request.Form["name"];

                var dbSerial = db.Series.Create();
                dbSerial.User_ID = userId[0];
                dbSerial.Name    = name;

                dbSerial.PublicS = Convert.ToInt32(Request.Form["Public"]);
                dbSerial.Seen    = 0;

                string source = "Images/" + Utile.RemoveSpecialCharacters(name + Path.GetExtension(Request.Form["source"])).ToLower();
                dbSerial.Source = source;

                bool serialAlreadyExists = db.Series.Any(s => s.Source == source && s.Name == name);

                if (!string.IsNullOrEmpty(name) && !serialAlreadyExists)
                {
                    SaveImage(Request.Form["source"], name);
                    db.Series.Add(dbSerial);
                    db.SaveChanges();
                }
            }
            else
            {
                ModelState.AddModelError("", "Incorrect format has been placed");
            }
            return(View(db.Series.ToList()));
        }