Exemplo n.º 1
0
        // GET: Appointments/Delete/5
        public async Task <ActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction("Index"));
                //return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            var currentUser       = LTDbApi.GetUser(User.Identity.Name);
            var cyclicAppointment = LTDbApi.GetCyclicAppointment(id.Value);

            if (!currentUser.IsAdmin && currentUser.Id != cyclicAppointment.Lecturer.LTUserId)
            {
                return(RedirectToAction("Index"));
                //return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            if (cyclicAppointment == null)
            {
                return(HttpNotFound());
            }
            CyclicAppointmentViewModel model = new CyclicAppointmentViewModel
            {
                DayOfWeek = cyclicAppointment.DayOfWeek,
                Location  = cyclicAppointment.Location,
                StartTime = cyclicAppointment.StartTime,
                EndTime   = cyclicAppointment.EndTime,
                Id        = cyclicAppointment.Id,
            };

            return(View(model));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Edit(CyclicAppointmentViewModel cyclicAppointmentViewModel)
        {
            if (ModelState.IsValid)
            {
                var currentUser       = LTDbApi.GetUser(User.Identity.Name);
                var cyclicAppointment = LTDbApi.GetCyclicAppointment(cyclicAppointmentViewModel.Id);

                if (!currentUser.IsAdmin && currentUser.Id != cyclicAppointment.Lecturer.LTUserId)
                {
                    return(RedirectToAction("Index"));
                    //return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
                }

                cyclicAppointment.DayOfWeek = cyclicAppointmentViewModel.DayOfWeek;
                cyclicAppointment.StartTime = cyclicAppointmentViewModel.StartTime;
                cyclicAppointment.EndTime   = cyclicAppointmentViewModel.EndTime;
                cyclicAppointment.Location  = cyclicAppointmentViewModel.Location;
                LTDbApi.UpdateCyclicAppointment(cyclicAppointment);
                return(RedirectToAction("Details", new { id = cyclicAppointment.LecturerId }));
            }
            return(View(cyclicAppointmentViewModel));
        }