Exemple #1
0
        // GET: Events/Create
        public ActionResult Create(int cat, int m, int y, int w)
        {
            ViewBag.subCategory = db.subCategories.Include(c => c.parent).Where(c => c.ID == cat).First();
            ViewBag.month = m;
            ViewBag.year = y;
            ViewBag.week = w;

            DateTime date = new DateTime(y, m, 1);
            DateTime start, end;
            if (w==1)
            {
                start = date;
                end = date.AddDays(7 - (int)date.DayOfWeek);
            }
            else
            {
                start = date.AddDays(1+(7 - (int)date.DayOfWeek)+(w-2)*7);
                end = date.AddDays(7 - (int)date.DayOfWeek + (w-1) * 7);
                while (end.Month != start.Month) end=end.AddDays(-1);
            }
            Event ev = new Event();
            ev.startDate = start;
            ev.endDate = end;
            return View(ev);
        }
Exemple #2
0
        public ActionResult Create(int cat, int m, int y, int w, Event @event)
        {
            Event ev = new Event();
            ev.name = @event.name;
            ev.description = @event.description;
            ev.startDate = @event.startDate;
            ev.endDate = @event.endDate;
            ev.subCategory = db.subCategories.Where(s => s.ID == cat).First();
            if (ModelState.IsValid)
            {
                db.events.Add(ev);
                db.SaveChanges();
                return RedirectToAction("Details", new {id=ev.ID, m=m, y=y });
            }

            return View(@event);
        }