Esempio n. 1
0
        public IActionResult Add(Activity Act)
        {
            if (ModelState.IsValid == false)
            {
                ViewBag.Errors = ModelState.Values;
                ViewBag.Status = true;
                return(View("AddPage"));
            }
            else
            {
                if (Act.date < DateTime.Now.Date)
                {
                    TempData["message"] = "Date cant be in the past";
                    return(RedirectToAction("AddPage"));
                }
                else
                {
                    Act.CreatedAt = DateTime.Now;
                    Act.UpdatedAt = DateTime.Now;
                    Act.UserId    = (int)HttpContext.Session.GetInt32("UserId");
                    _context.Add(Act);
                    _context.SaveChanges();
                    TempData["message"] = "Sucessfully added a new activity";
                }
            }
            Activity Activity = new Activity();

            Activity = _context.activities.Where(activity => activity.CreatedAt.Ticks == Act.CreatedAt.Ticks).SingleOrDefault();
            int ID = Activity.id;

            return(RedirectToAction("Page", new { @ActId = ID }));
        }
        public IHttpActionResult PutDog(int id, Dog dog)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != dog.DogId)
            {
                return(BadRequest());
            }

            db.Entry(dog).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DogExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 3
0
        public IHttpActionResult Post(Dog dog)
        {
            db.Dogs.Add(dog);
            db.SaveChanges();

            return(Created("Get", dog));
        }
Esempio n. 4
0
 public ActionResult EditDisplay([Bind(Include = "DogId,nickName,Breed")] Dog dog)
 {
     if (ModelState.IsValid)
     {
         db.Entry(dog).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Display"));
     }
     return(View(dog));
 }
 public ActionResult Create(Dog dog)
 {
     if (ModelState.IsValid)
     {
         db.Dogs.Add(dog);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(dog));
 }
Esempio n. 6
0
        public ActionResult Create([Bind(Include = "Id,Age,Name")] ElCoso elCoso)
        {
            if (ModelState.IsValid)
            {
                db.ElCosoes.Add(elCoso);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(elCoso));
        }
Esempio n. 7
0
        public ActionResult Create([Bind(Include = "ID,Title,ReleaseDate,Genre,Price")] Dog dog)
        {
            if (ModelState.IsValid)
            {
                db.Dogs.Add(dog);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(dog));
        }
Esempio n. 8
0
        public IActionResult CreateBlog(Blog newBlog)
        {
            Blog MyBlog = new Blog {
                UserId  = newBlog.UserId,
                Title   = newBlog.Title,
                Content = newBlog.Content
            };

            _context.Blogs.Add(MyBlog);
            _context.SaveChanges();

            return(RedirectToAction("Blog"));
        }
Esempio n. 9
0
 public IActionResult AddPark(ParkViewModel model, Park newPark)
 {
     if (ModelState.IsValid)
     {
         _context.Parks.Add(newPark);
         _context.SaveChanges();
         return(RedirectToAction("Parks"));
     }
     else
     {
         ViewBag.errors = ModelState.Values;
         return(View("Parks"));
     }
 }
Esempio n. 10
0
        public async Task <IActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await userManager.FindByNameAsync(model.Username);

                if (user != null)
                {
                    ModelState.AddModelError("", "Username already exists!");
                    return(View());
                }

                user = new User()
                {
                    FirstName = model.FirstName,
                    LastName  = model.LastName,
                    UserName  = model.Username
                };

                var result = await userManager.CreateAsync(user, model.Password);

                if (result == IdentityResult.Success)
                {
                    context.SaveChanges();
                    return(RedirectToAction("Login", "Account"));
                }
            }
            ModelState.AddModelError("", "Failed to register!");
            return(View());
        }
Esempio n. 11
0
        public void SetRole(Role role, int id)
        {
            var account = context.Accounts.Where(x => x.Id == id).FirstOrDefault();

            account.Role = role;
            context.SaveChanges();
        }
Esempio n. 12
0
 public IActionResult Register(RegisterViewModel model)
 {
     if (_context.users.Where(u => u.email == model.email).SingleOrDefault() != null)
     {
         TempData["message"] = "Email is taken!";
         return(RedirectToAction("Index"));
     }
     else
     {
         if (ModelState.IsValid)
         {
             User NewUser = new User {
                 FirstName = model.FirstName,
                 LastName  = model.LastName,
                 email     = model.email,
                 password  = model.password
             };
             NewUser.CreatedAt = DateTime.Now;
             NewUser.UpdatedAt = DateTime.Now;
             _context.Add(NewUser);
             _context.SaveChanges();
             User current = _context.users.Where(u => u.email == model.email).SingleOrDefault();
             HttpContext.Session.SetInt32("UserId", current.id);
             TempData["message"] = "You have successfully registered!";
             return(RedirectToAction("Activity", "Activity"));
         }
         ViewBag.Errors = ModelState.Values;
         ViewBag.Status = true;
         return(View("Index"));
     }
 }
Esempio n. 13
0
 public IActionResult Register(RegisterViewModel model, User NewUser)
 {
     if (ModelState.IsValid)
     {
         User CurrUser = _context.Users.SingleOrDefault(user => user.Email == model.Email);
         if (CurrUser == null)
         {
             _context.Users.Add(NewUser);
             _context.SaveChanges();
             User currUser = _context.Users.SingleOrDefault(user => user.Email == model.Email);
             HttpContext.Session.SetInt32("CurrUserId", (int)currUser.UserId);
             return(RedirectToAction("Dashboard"));
         }
         else
         {
             List <string> errors = new List <string>();
             ViewBag.errors    = errors;
             ViewBag.logerrors = "Email must be unique!";
             return(View("Index"));
         }
     }
     else
     {
         ViewBag.errors = ModelState.Values;
         return(View("Index"));
     }
 }
 public ActionResult Create([Bind(Include = "BreedId,BreedName,Country,Photo")] Breed breeds)
 {
     try
     {
         if (ModelState.IsValid)
         {
             db.Breeds.Add(breeds);
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
     }
     catch (DataException)
     {
         ModelState.AddModelError("",
                                  "Unable to save changes. Try again.");
     }
     return(View(breeds));
 }
 public ActionResult Create([Bind(Include = "Id,Name,NumberofDogs,DogId")] Users users)
 {
     try
     {
         if (ModelState.IsValid)
         {
             db.User.Add(users);
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
     }
     catch (DataException)
     {
         ModelState.AddModelError("",
                                  "Unable to save changes. Try again.");
     }
     return(View(users));
 }
Esempio n. 16
0
        public ActionResult Create([Bind(Include = "Id,Name, Breed")] Dog dog, string[] selectedCharacteristic)
        {
            if (selectedCharacteristic != null)
            {
                dog.Characteristics = new List <Characteristic>();
                foreach (var item in selectedCharacteristic)
                {
                    var characteristicsToAdd = db.Characteristics.Find(int.Parse(item));
                    dog.Characteristics.Add(characteristicsToAdd);
                }
            }

            if (ModelState.IsValid)
            {
                dog.Breed = db.Breeds.First(r => r.Id == dog.Breed.Id);
                db.Dogs.Add(dog);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(dog));
        }
Esempio n. 17
0
        public JsonResult PreRegister(RegisterViewModel RegAuth)
        {
            Dictionary <string, string> response = new Dictionary <string, string>();

            response.Add("errors", "True");
            response.Add("Name", "");
            response.Add("Email", "");
            response.Add("Password", "");
            response.Add("PassConf", "");
            if (ModelState.IsValid)
            {
                Dog CurrentDog = _context.dogs.Where(dogs => dogs.Email == RegAuth.Email).SingleOrDefault();
                if (CurrentDog != null)
                {
                    response["Email"] = "That email already exists";
                }
                else
                {
                    Dog NewDog = new Dog
                    {
                        Name       = RegAuth.Name,
                        Email      = RegAuth.Email,
                        Password   = RegAuth.Password,
                        created_at = DateTime.Now,
                        updated_at = DateTime.Now
                    };
                    PasswordHasher <Dog> Hasher = new PasswordHasher <Dog>();
                    NewDog.Password    = Hasher.HashPassword(NewDog, NewDog.Password);
                    ViewBag.ProfileDog = NewDog;
                    _context.dogs.Add(NewDog);
                    _context.SaveChanges();
                    CurrentDog = _context.dogs.SingleOrDefault(dog => dog.Name == NewDog.Name);
                    HttpContext.Session.SetInt32("CurrentDog", CurrentDog.DogId);
                    response["errors"] = "False";
                }
            }
            else
            {
                foreach (string key in ViewData.ModelState.Keys)
                {
                    try {
                        string error = ViewData.ModelState.Keys.Where(k => k == key).Select(k => ModelState[k].Errors[0].ErrorMessage).First();
                        response[key] = error;
                    } catch {
                        continue;
                    }
                }
            }
            return(Json(response));
        }
Esempio n. 18
0
 public void CreateNewItem(Sheet sheet)
 {
     dogContext.SheetData.Add(sheet);
     dogContext.SaveChanges();
 }