コード例 #1
0
ファイル: EventController.cs プロジェクト: kossov/PartyMate
        public ActionResult Add(int id, EventBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return this.View(model);
            }

            var genreInModel = this.genres.All()
                .Where(g => g.Genre == model.Genre)
                .FirstOrDefault();

            if (genreInModel == null)
            {
                genreInModel = new MusicGenre()
                {
                    Genre = model.Genre
                };

                this.genres.Add(genreInModel);
            }

            Image image = null;

            if (model.Image != null)
            {
                using (var memory = new MemoryStream())
                {
                    model.Image.InputStream.CopyTo(memory);
                    var contentAsArray = memory.GetBuffer();

                    image = new Image
                    {
                        Content = contentAsArray
                    };
                }
            }

            this.images.Add(image);

            var club = this.clubs.GetById(id);

            var evnt = new Event()
            {
                Club = club,
                Title = model.Title,
                Description = model.Description,
                StartsAt = model.StartsAt,
                EventOwner = model.EventOwner,
                EntranceFee = model.EntranceFee,
                MusicGenre = genreInModel,
                Url = model.Url,
                Image = image
            };

            this.events.Add(evnt);
            this.events.SaveChanges();

            this.TempData["Notification"] = "Event added successfully!";
            return this.RedirectToAction("Index", "Home");
        }
コード例 #2
0
ファイル: EventController.cs プロジェクト: kossov/PartyMate
        public ActionResult Add(int id)
        {
            var model = new EventBindingModel();
            model.Id = id;

            return this.View(model);
        }