Exemple #1
0
        public ActionResult Duplicate(Course course)
        {
            if (IsAuthorized(course.ID))
            {
                if (ModelState.IsValid)
                {
                    try
                    {
                        course.Responsible = (int)SessionManager.GetCurrentUserId(HttpContext.User.Identity.Name);
                        int id_course = CourseModel.CreateCourse(course);
                        List <SlotRange> slotRanges = course.GetSlotRangesForCourse();
                        int days = 0;
                        foreach (SlotRange sr in slotRanges)
                        {
                            if (days == 0)
                            {
                                TimeSpan span = course.DuplDestDate - sr.StartRes;
                                days = (int)span.TotalDays;
                            }

                            SlotRangeModel.DuplicateSlotRange(sr, days, id_course);
                        }
                        return(RedirectToAction("Index"));
                    }
                    catch (GrException gex)
                    {
                        System.Diagnostics.Debug.WriteLine(gex.UserMessage);
                        System.Diagnostics.Debug.WriteLine(gex.StackTrace);
                        ModelState.AddModelError("", gex.UserMessage);
                        return(View(course));
                    }
                }
                else
                {
                    // addinge extra error message here in case JS is deactivated on client.
                    ModelState.AddModelError("", "vous avez envoyé des données invalides");
                    return(View(course));
                }
            }
            else
            {
                SessionManager.RedirectAccessDenied(HttpContext.Request.RequestContext);
                return(null);
            }
        }
        public ActionResult Duplicate(int id, SlotRange target)
        {
            SlotRange source = SlotRangeModel.GetSlotRange(id);

            if (source == null)
            {
                return(View("NoSuchRange"));
            }
            int?rId = source.GetResponsible();

            if (IsAuthorized(source))
            {
                TimeSpan span = target.StartRes - source.StartRes;
                int      days = (int)span.TotalDays;
                SlotRangeModel.DuplicateSlotRange(source, days, source.IdCourse);
                return(RedirectToAction("CourseRanges", new { id = source.IdCourse }));
            }
            else
            {
                SessionManager.RedirectAccessDenied(HttpContext.Request.RequestContext);
                return(null);
            }
        }