Esempio n. 1
0
        public ActionResult Create(int? locationID)
        {
            if (locationID == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }

            var Location = db.Locations.Find(locationID);

            if (Location == null)
            {
                return HttpNotFound();
            }

            Event one_event = new Event();

            one_event.LocationId = Location.ID;

            var query2 = from a in db.Monsters
                         from b in db.Images
                         where a.ImageId == b.ID
                         select new DetailsMonsterViewModel
                         {
                            Monster = a,
                            Image = b
                         };

            var monsters = query2.ToList();

            CreateEventViewModel model = new CreateEventViewModel();

            model.Location = Location;
            model.Event = one_event;
            model.Monsters = monsters;

            return View(model);
        }
Esempio n. 2
0
        public ActionResult Create(Event one_event)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    db.Events.Add(one_event);
                    db.SaveChanges();

                    FlashMessageHelper.SetMessage(this, FlashMessageType.Success, "Zapisanie nowych danych przebiegło pomyślnie.");
                    return RedirectToAction("Index");
                }
                FlashMessageHelper.SetMessage(this, FlashMessageType.Info, "Nie można zapisać nowych danych. Należy poprawić zaistniałe błędy.");
            }
            catch (Exception)
            {
                FlashMessageHelper.SetMessage(this, FlashMessageType.Danger, "Wystąpił nieoczekiwany błąd związany z zapisem nowych danych.");
            }

            var query = from a in db.Locations
                        where a.ID == one_event.LocationId
                        select a;

            var fail_event = query.FirstOrDefault();

            CreateEventViewModel setItemViewModel = new CreateEventViewModel()
            {
                Location = fail_event,
                Event = one_event
            };

            return View(setItemViewModel);
        }
Esempio n. 3
0
        public ActionResult Edit(Event oneEvent)
        {
            var query = from i in db.Events
                        where i.Id == oneEvent.Id
                        select i;

            if (!query.Any())
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }

            try
            {
                if (ModelState.IsValid)
                {
                    db.Entry(oneEvent).State = EntityState.Modified;
                    db.SaveChanges();

                    FlashMessageHelper.SetMessage(this, FlashMessageType.Success, "Aktualizacja danych przebiegła pomyślnie.");
                    return RedirectToAction("Index");
                }

                FlashMessageHelper.SetMessage(this, FlashMessageType.Info, "Nie można zaktualizować danych. Należy poprawić zaistniałe błędy.");
            }
            catch (DbUpdateConcurrencyException)
            {
                FlashMessageHelper.SetMessage(this, FlashMessageType.Warning, "Dane został zaktualizowane przez inną osobę. Należy odświeżyć stronę w celu wczytania nowych danych.");
            }
            catch (Exception)
            {
                FlashMessageHelper.SetMessage(this, FlashMessageType.Danger, "Wystąpił nieoczekiwany błąd związany z aktualizowaniem danych.");
            }

            var query2 = from a in db.Locations
                        where a.ID == oneEvent.LocationId
                        select a;

            var fail_event = query2.FirstOrDefault();

            CreateEventViewModel setItemViewModel = new CreateEventViewModel()
            {
                Location = fail_event,
                Event = oneEvent
            };

            return View(setItemViewModel);
        }
Esempio n. 4
0
        public ActionResult Edit(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            var oneEvent = db.Events.Find(id);

            if (oneEvent == null)
            {
                return HttpNotFound();
            }

            var query2 = from a in db.Monsters
                         from b in db.Images
                         where a.ImageId == b.ID
                         select new DetailsMonsterViewModel
                         {
                             Monster = a,
                             Image = b
                         };
            var Location = db.Locations.Find(oneEvent.LocationId);

            var monsters = query2.ToList();

            CreateEventViewModel model = new CreateEventViewModel();

            model.Location = Location;
            model.Event = oneEvent;
            model.Monsters = monsters;

            return View(model);
        }