Example #1
0
        public ActionResult AddEventToOrgCalendar()
        {
            try
            {
                var sess = Session["OrgId"].ToString();
                int i    = Convert.ToInt32(sess);

                var orgschcalendar = new OrgSchCalendar();
                // Get all the groups from the database
                var grp = db.OrgGroups.Where(c => c.OrgId == i).ToList();
                // Get all the Catergory from the database
                var calendarcategorys = db.CalendarCategorys.ToList();
                // Initialize the view model
                var addeventtoorgcalviewmodel = new AddNewOrgSchCalViewModel
                {
                    OrgSchCalendar    = orgschcalendar,
                    CalendarCategorys = calendarcategorys,
                    OrgGroups         = grp.Select(x => new OrgGroup()
                    {
                        OrgGroupId = x.OrgGroupId,
                        OrgId      = x.OrgId,
                        GroupName  = x.GroupName
                    }).ToList()
                };
                ViewBag.CalendarCategoryId = new SelectList(db.CalendarCategorys, "CalendarCategoryId", "CategoryName");
                ViewBag.OrgId = new SelectList(db.Orgs, "OrgId", "OrgName");
                return(PartialView("~/Views/Shared/PartialViewsForms/_AddEventToOrgCalendar.cshtml", addeventtoorgcalviewmodel));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(Redirect("~/ErrorHandler.html"));
            }
        }
Example #2
0
        // Update past events by sys admin and set the archived glad
        public ActionResult UpdateEvents()
        {
            try
            {
                if (Session["OrgId"] == null)
                {
                    return(RedirectToAction("Signin", "Access"));
                }
                if ((int)Session["OrgId"] != 23)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }
                if ((int)Session["OrgId"] == 23)
                {
                    // LOOP THROUGH LIST OF EVENTS IN DB
                    var orgschevnts     = db.OrgSchCalendars.Select(x => x.OrgSchCalendarId).ToList();
                    var orgschevntslist = new List <int>(orgschevnts);

                    foreach (var evntid in orgschevnts)
                    {
                        // GET EVENT DATE
                        var eventdate = db.OrgSchCalendars.Where(x => x.OrgSchCalendarId == evntid).Select(x => x.EventDate).FirstOrDefault();
                        // GET VALUE OF ISSCHEDULE
                        var eventid = db.OrgSchCalendars.AsNoTracking().Where(x => x.OrgSchCalendarId == evntid).FirstOrDefault();
                        if (eventdate < DateTime.Now)
                        {
                            var schevnt = new OrgSchCalendar
                            {
                                OrgSchCalendarId   = eventid.OrgSchCalendarId,
                                CalendarCategoryId = eventid.CalendarCategoryId,
                                OrgId           = eventid.OrgId,
                                Name            = eventid.Name,
                                CreatorId       = eventid.CreatorId,
                                CreatorFullName = eventid.CreatorFullName,
                                CreationDate    = eventid.CreationDate,
                                IsRecurring     = eventid.IsRecurring,
                                Frequency       = eventid.Frequency,
                                SendAsEmail     = eventid.SendAsEmail,
                                EventDate       = eventid.EventDate,
                                Description     = eventid.Description,
                                EventTime       = eventid.EventTime,
                                Isarchived      = true
                            };
                            eventid = schevnt;
                            db.Entry(eventid).State = EntityState.Modified;
                            db.SaveChanges();
                        }
                    }
                    return(RedirectToAction("SysAdminSetUp", "Home"));
                }
                return(new HttpStatusCodeResult(204));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(Redirect("~/ErrorHandler.html"));
            }
        }
Example #3
0
        public ActionResult DeleteConfirmed(int?Id)
        {
            try
            {
                if (Request.Browser.IsMobileDevice == true && Session["IsTester"] == null)
                {
                    return(RedirectToAction("WrongDevice", "Orgs"));
                }
                if (Session["OrgId"] == null)
                {
                    return(RedirectToAction("Signin", "Access"));
                }
                var sess = Session["OrgId"].ToString();
                int i    = Convert.ToInt32(sess);

                OrgSchCalendar orgSchCalendar = db.OrgSchCalendars.Find(Id);
                db.OrgSchCalendars.Remove(orgSchCalendar);
                db.SaveChanges();

                //// UPON DELETING A CALNDR EVENT - LOG THE EVENT
                var orgeventlog = new Org_Events_Log()
                {
                    Org_Event_SubjectId       = orgSchCalendar.OrgSchCalendarId.ToString(),
                    Org_Event_SubjectName     = orgSchCalendar.Name,
                    Org_Event_TriggeredbyId   = Session["RegisteredUserId"].ToString(),
                    Org_Event_TriggeredbyName = Session["FullName"].ToString(),
                    Org_Event_Time            = DateTime.Now,
                    OrgId            = Session["OrgId"].ToString(),
                    Org_Events_Types = Org_Events_Types.Calendar_Event_Deleted
                };
                db.Org_Events_Logs.Add(orgeventlog);
                db.SaveChanges();
                return(RedirectToAction("Index", "Orgs", new { id = i }));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(Redirect("~/ErrorHandler.html"));
            }
        }
Example #4
0
        public ActionResult Edit(OrgSchCalendar orgSchCalendar)
        {
            try
            {
                if (Request.Browser.IsMobileDevice == true && Session["IsTester"] == null)
                {
                    return(RedirectToAction("WrongDevice", "Orgs"));
                }
                if (Session["OrgId"] == null)
                {
                    return(RedirectToAction("Signin", "Access"));
                }
                var sess = Session["OrgId"].ToString();
                int i    = Convert.ToInt32(sess);

                // LOOP THRU LIST OF RECORD IN TABLE AND REMOVE
                var orgschcalid = db.OrgSchCalndrGrps
                                  .Where(x => x.OrgSchCalendarId == orgSchCalendar.OrgSchCalendarId)
                                  .Where(x => x.OrgId == i)
                                  .Select(x => x.OrgSchCalndrGrpId)
                                  .ToList();
                var orgschcalidtolist = new List <int>(orgschcalid);

                foreach (var recrd in orgschcalid)
                {
                    var removercrd = db.OrgSchCalndrGrps
                                     .Where(x => x.OrgSchCalndrGrpId == recrd)
                                     .Where(x => x.OrgId == i)
                                     .Select(x => x.OrgSchCalndrGrpId)
                                     .FirstOrDefault();

                    OrgSchCalndrGrp orgschcalndrgrp = db.OrgSchCalndrGrps.Find(removercrd);
                    db.OrgSchCalndrGrps.Remove(orgschcalndrgrp);
                }

                // LOOP THRU LIST OF GROUPS PROVIDED
                var grps       = orgSchCalendar.OrgGroups.Select(x => x.OrgGroupId).ToList();
                var grpstolist = new List <int>(grps);

                foreach (var grp in grps)
                {
                    // GET VALUE OF IS-SELECTED
                    var isselected = orgSchCalendar.OrgGroups
                                     .Where(x => grp == x.OrgGroupId)
                                     .Select(x => x.IsSelected)
                                     .FirstOrDefault();

                    if (isselected == true)
                    {
                        var orgschcalndrGrps = new OrgSchCalndrGrp()
                        {
                            OrgSchCalendarId = orgSchCalendar.OrgSchCalendarId,
                            OrgGroupId       = grp,
                            OrgId            = i,
                        };
                        db.OrgSchCalndrGrps.Add(orgschcalndrGrps);
                        db.SaveChanges();
                    }
                }
                if (!(ModelState.IsValid) || ModelState.IsValid)
                {
                    db.Entry(orgSchCalendar).State = EntityState.Modified;
                    db.SaveChanges();

                    //// UPON EDITING A CALNDR EVENT - LOG THE EVENT -
                    var orgeventlog = new Org_Events_Log()
                    {
                        Org_Event_SubjectId       = orgSchCalendar.OrgSchCalendarId.ToString(),
                        Org_Event_SubjectName     = orgSchCalendar.Name,
                        Org_Event_TriggeredbyId   = Session["RegisteredUserId"].ToString(),
                        Org_Event_TriggeredbyName = Session["FullName"].ToString(),
                        Org_Event_Time            = DateTime.Now,
                        OrgId            = Session["OrgId"].ToString(),
                        Org_Events_Types = Org_Events_Types.Calendar_Event_Edited
                    };
                    db.Org_Events_Logs.Add(orgeventlog);
                    db.SaveChanges();

                    return(RedirectToAction("Index", "Orgs", new { id = i }));
                }
                ViewBag.CalendarCategoryId = new SelectList(db.CalendarCategorys, "CalendarCategoryId", "CategoryName", orgSchCalendar.CalendarCategoryId);
                ViewBag.OrgId = new SelectList(db.Orgs, "OrgId", "OrgName", orgSchCalendar.OrgId);
                return(View(orgSchCalendar));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(Redirect("~/ErrorHandler.html"));
            }
        }
Example #5
0
        public ActionResult EditOrgSchCal(int Id)
        {
            try
            {
                if (Request.Browser.IsMobileDevice == true && Session["IsTester"] == null)
                {
                    return(RedirectToAction("WrongDevice", "Orgs"));
                }
                if (Session["OrgId"] == null)
                {
                    return(RedirectToAction("Signin", "Access"));
                }
                var sess = Session["OrgId"].ToString();
                int i    = Convert.ToInt32(sess);

                var edtcalevent = db.OrgSchCalendars
                                  .Include(x => x.CalendarCategory)
                                  .Where(x => x.OrgSchCalendarId == Id)
                                  .FirstOrDefault();

                var orgschcalendar = new OrgSchCalendar();
                // Get all the groups from the database
                var grp = db.OrgGroups.Where(c => c.OrgId == i).ToList();


                // Get all the Catergory from the database
                var calendarcategorys = db.CalendarCategorys.ToList();
                // Initialize the view model
                var editeventorgcalviewmodel = new EditOrgSchCalViewModel
                {
                    OrgSchCalendarId   = edtcalevent.OrgSchCalendarId,
                    CalendarCategoryId = edtcalevent.CalendarCategoryId,
                    OrgId           = edtcalevent.OrgId,
                    Name            = edtcalevent.Name,
                    CreatorId       = edtcalevent.CreatorId,
                    CreatorFullName = edtcalevent.CreatorFullName,
                    Description     = edtcalevent.Description,
                    EventDate       = edtcalevent.EventDate,
                    EventTime       = edtcalevent.EventTime,
                    CreationDate    = edtcalevent.CreationDate,
                    IsRecurring     = edtcalevent.IsRecurring,
                    Frequency       = edtcalevent.Frequency,
                    SendAsEmail     = edtcalevent.SendAsEmail,
                    Isarchived      = edtcalevent.Isarchived,

                    OrgGroups = grp.Select(x => new OrgGroup()
                    {
                        OrgGroupId = x.OrgGroupId,
                        OrgId      = x.OrgId,
                        GroupName  = x.GroupName,
                        IsSelected = x.IsSelected
                    }).ToList()
                };

                foreach (var group in editeventorgcalviewmodel.OrgGroups)
                {
                    int groupCount = editeventorgcalviewmodel.OrgGroups.Count();
                }
                foreach (var item in editeventorgcalviewmodel.OrgGroups)
                {
                    var isselected = db.OrgSchCalndrGrps
                                     .Where(x => x.OrgGroupId == item.OrgGroupId)
                                     .Where(x => x.OrgSchCalendarId == Id)
                                     .Where(X => X.OrgId == i)
                                     .Select(x => x.OrgSchCalndrGrpId)
                                     .Count();

                    if (isselected == 0)
                    {
                        item.IsSelected = false;
                        editeventorgcalviewmodel.CalendarCategoryId = edtcalevent.CalendarCategoryId;
                    }
                    else
                    {
                        item.IsSelected = true;
                        editeventorgcalviewmodel.CalendarCategoryId = edtcalevent.CalendarCategoryId;
                    }
                }
                ViewBag.CalendarCategoryId = new SelectList(db.CalendarCategorys, "CalendarCategoryId", "CategoryName");
                ViewBag.OrgId = new SelectList(db.Orgs, "OrgId", "OrgName");
                return(PartialView("~/Views/Shared/PartialViewsForms/_EditOrgSchCal.cshtml", editeventorgcalviewmodel));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(Redirect("~/ErrorHandler.html"));
            }
        }