// GET: ScheduleItems/Create
        public ActionResult Create(int? scheduleId)
        {
            Schedule schedule = db.Schedules.Find(scheduleId);

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

            if (User.Identity.IsAuthenticated)
            {
                var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(db));
                var currentUser = userManager.FindById(User.Identity.GetUserId());
                if (schedule.Department.Bosses.Contains(currentUser))
                {
                    var model = new ScheduleItemEditViewmodel();
                    model.WeekDays = new List<ScheduleItemWeekday>();
                    foreach (var weekDay in db.ScheduleWeekDays.ToList())
                    {
                        model.WeekDays.Add(new ScheduleItemWeekday() { Id = weekDay.Id, Checked = false, Name = weekDay.Description });
                    }

                    //ViewBag.ScheduleId = new SelectList(db.Schedules, "Id", "Id",scheduleId);
                    ViewBag.ScheduleId = db.Schedules.ToList().Select(q => new SelectListItem()
                    {
                        Value = q.Id.ToString(),
                        Text = q.Department.Name + ((q.Group == null) ? "" : ":" + q.Group.Name) + " - " + q.StartTime.ToShortDateString() + " : " + (q.EndTime == null ? "Ongoing" : q.EndTime.GetValueOrDefault().ToShortDateString()),
                        Selected = (q.Id == scheduleId)
                    });
                    return View(model);
                }
                else
                {
                    return new HttpStatusCodeResult(HttpStatusCode.Unauthorized);
                }
            }
            else
            {
                return new HttpStatusCodeResult(HttpStatusCode.Unauthorized);
            }
        }
Esempio n. 2
0
 public ScheduleItem(ScheduleItemEditViewmodel that)
 {
     this.Id = that.Id;
     this.StartTime = that.StartTime;
     this.EndTime = that.EndTime;
     this.Description = that.Description;
     this.ScheduleId = that.ScheduleId;
     this.WeekDays = new List<ScheduleDayOfWeek>();
 }