Exemple #1
0
        // GET: /Administration/HungryGroups/Edit/5
        public ActionResult Edit(int?id)
        {
            HungryGroupViewModel hungryGroupModel = new HungryGroupViewModel();

            hungryGroupModel.EatItemsDropdown = GetEatTypeItems();
            hungryGroupModel.PlacesDropdown   = GetPlaces();

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            HungryGroup hungrygroup = this.Db.HungryGroupRepository.All().FirstOrDefault(x => x.Id == id);

            if (hungrygroup == null)
            {
                return(HttpNotFound());
            }
            else
            {
                hungryGroupModel.EatTime = hungrygroup.EatTime;
                hungryGroupModel.EatItemsDropdown.FirstOrDefault(x => x.Text == hungryGroupModel.EatTime.ToString()).Selected = true;
                hungryGroupModel.StartingTime = hungrygroup.StartingTime;
            }

            return(View(hungryGroupModel));
        }
Exemple #2
0
        public ActionResult DeleteConfirmed(int id)
        {
            HungryGroup hungrygroup = db.HungryGroups.Find(id);

            db.HungryGroups.Remove(hungrygroup);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemple #3
0
        // GET: /Administration/HungryGroups/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            HungryGroup hungrygroup = db.HungryGroups.Find(id);

            if (hungrygroup == null)
            {
                return(HttpNotFound());
            }
            return(View(hungrygroup));
        }
        public ActionResult Index(CreateGroupViewModel model)
        {
            var chosenPlace = this.Db.PlaceRepository.All().FirstOrDefault(x => x.Name == model.PlacePlaceholder);
            var userId      = User.Identity.GetUserId();
            var user        = this.Db.UsersRepository.All().FirstOrDefault(x => x.Id == userId);

            var newGroup = new HungryGroup
            {
                Creator      = user,
                Place        = chosenPlace,
                StartingTime = model.StartingTime,
                EatTime      = chosenPlace.EatTime
            };

            this.Db.HungryGroupRepository.Add(newGroup);
            this.Db.SaveChanges();

            return(View());
        }
Exemple #5
0
        public ActionResult Edit(HungryGroupViewModel hungrygroup)
        {
            var place = db.Places.FirstOrDefault(x => x.Id == hungrygroup.Id);

            HungryGroup editedHungryGroup = new HungryGroup()
            {
                Creator      = hungrygroup.Creator,
                EatTime      = hungrygroup.EatTime,
                HungryUsers  = hungrygroup.HungryUsers,
                Id           = hungrygroup.Id,
                Place        = place,
                StartingTime = hungrygroup.StartingTime
            };

            if (ModelState.IsValid)
            {
                db.Entry(editedHungryGroup).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(hungrygroup));
        }
Exemple #6
0
        public ActionResult Create(HungryGroupViewModel hungrygroup)
        {
            if (ModelState.IsValid)
            {
                hungrygroup.Creator = this.Db.UsersRepository.All().FirstOrDefault(x => x.UserName == User.Identity.Name);

                hungrygroup.Place = this.Db.PlaceRepository.All().FirstOrDefault(x => x.Id == hungrygroup.PlaceId);

                HungryGroup newGroup = new HungryGroup()
                {
                    Creator      = hungrygroup.Creator,
                    EatTime      = hungrygroup.EatTime,
                    HungryUsers  = hungrygroup.HungryUsers,
                    Id           = hungrygroup.Id,
                    Place        = hungrygroup.Place,
                    StartingTime = hungrygroup.StartingTime
                };
                this.Db.HungryGroupRepository.Add(newGroup);
                this.Db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(hungrygroup));
        }