コード例 #1
0
        public ActionResult Create(EventInputModel model)
        {
            if (!this.ModelState.IsValid)
            {
                this.View(model);
            }

            var restaurantId = this.User.Identity.GetUserId();

            DateTime baseDate = DateTime.UtcNow;
            var thisWeekStart = baseDate.AddDays(-(int)baseDate.DayOfWeek);
            var thisWeekEnd = thisWeekStart.AddDays(7).AddSeconds(-1);

            var restaurant = this.restaurants.GetById(restaurantId);

            var dbevent = new Event
            {
                Name = model.Name,
                Description = model.Description,
                RestaurantId = restaurantId,
                ExpirationDate = thisWeekEnd,
                Participants = restaurant.RegularUsers
            };

            this.events.Create(dbevent);

            return this.RedirectToAction("ListEvents", "ListEvents");
        }
コード例 #2
0
        public ActionResult Create(EventViewModel model, HttpPostedFileBase upload)
        {
            if (this.ModelState.IsValid)
            {
                var eventToAdd = new Event
                {
                    Title = model.Title,
                    Description = HttpUtility.HtmlDecode(model.Description),
                    CreatorId = this.User.Identity.GetUserId()
                };

                if (upload != null && upload.ContentLength > 0)
                {
                    var photo = new Data.Models.File
                    {
                        FileName = Path.GetFileName(upload.FileName),
                        FileType = FileType.Photo,
                        ContentType = upload.ContentType
                    };

                    using (var reader = new BinaryReader(upload.InputStream))
                    {
                        photo.Content = reader.ReadBytes(upload.ContentLength);
                    }

                    eventToAdd.Photo = photo;
                    this.events.Add(eventToAdd);
                }

                return this.RedirectToAction("Index");
            }

            return this.View(model);
        }
コード例 #3
0
        public ActionResult Events_Destroy([DataSourceRequest]DataSourceRequest request, Event eventToDelete)
        {
            this.events.Delete(eventToDelete);

            return this.Json(new[] { eventToDelete }.ToDataSourceResult(request, this.ModelState));
        }