Ejemplo n.º 1
0
        public virtual JsonResult Event_Destroy([DataSourceRequest] DataSourceRequest request, CalEventViewModel eventViewModel)
        {
            if (ModelState.IsValid)
            {
                //int fromCalendarId = 0;
                string fromCalendar = string.Empty;
                int fromCalendarId = (int)eventViewModel.CalenderUser;
                using (var OrderMangtDB = new OrderMgntEntities())
                {
                    //fromCalendarId = (int)OrderMangtDB.Events.First(m => m.Row_Id == eventRowId).CalendarId;
                    fromCalendar = OrderMangtDB.Calendars.SingleOrDefault(m => m.Row_Id == fromCalendarId).Name;
                }

                try
                {
                    if (!string.IsNullOrEmpty(eventViewModel.EventId))
                    {

                        string eventid = eventViewModel.EventId;

                        var objGoogleCal = new GoogleServiceMethodCalls();
                        objGoogleCal.DeleteEvent(eventid, fromCalendar);

                        using (var OrderMangtDB = new OrderMgntEntities())
                        {
                            var Events =
                                     (from oEvents in OrderMangtDB.Events
                                      where oEvents.EventId == eventid && oEvents.CalendarId == fromCalendarId
                                      select oEvents).ToList();

                            foreach (var Event in Events)
                            {
                                Event.Status = "cancelled";

                            }
                            OrderMangtDB.SaveChanges();

                            int LoggedInUserId = (int)UserManager.Current().Row_Id;
                            DBLogger(eventViewModel.EventId, eventViewModel.Title, "Cancelled Event", LoggedInUserId, fromCalendar, fromCalendar);

                        }

                        // Check if more than one rec is exist
                        //  var AllEventByCalendarIdAndEventId = _scheduler.GetAllEventByCalendarIdAndEventId(eventid, CalendarId);
                        //    DeleteEvent(eventViewModel.EventId, fromCalendar, fromCalendarId);

                    }
                    else if (!string.IsNullOrEmpty(eventViewModel.GoogleEventid))
                    {
                        DeleteEvent(eventViewModel.GoogleEventid, fromCalendar, fromCalendarId);
                        int LoggedInUserId = (int)UserManager.Current().Row_Id;
                        DBLogger(eventViewModel.GoogleEventid, eventViewModel.Title, "Cancelled Event", LoggedInUserId, fromCalendar, fromCalendar);

                    }

                }
                catch (Exception ex)
                {

                    string msg = ex.Message;
                    Logger(msg);
                }

            }

            return Json(new[] { eventViewModel }.ToDataSourceResult(request, ModelState));
        }
Ejemplo n.º 2
0
        //public virtual JsonResult Event_Read(DataSourceRequest request, string chkselected, DateTime start, DateTime end)
        //{
        //    return null;
        //}
        public virtual JsonResult Event_Read(DataSourceRequest request, string chkselected, DateTime start, DateTime end, string Search)
        {
            List<EventException> lstException = new List<EventException>();
            IList<CalEventViewModel> events = new List<CalEventViewModel>();

              //  string Search = "";
            if (Search.Length > 0)
            {
                {
                    var tasks = _scheduler.GetAllEventBySearch(Search);
                    var preExceptionList = _scheduler.GetEventExceptions();
                    var getAllEventException = _scheduler.GetAllEventException();
                    var colmaster = _scheduler.GetAllColor();
                    var usercalenderlst = _scheduler.GetAllCalendarUser();
                    if (tasks.ToList().Count > 0)
                    {
                        var reccEvents = tasks.Where(x => !string.IsNullOrEmpty(x.Recurrence)).ToList();

                        Dictionary<string, List<string>> test = new Dictionary<string, List<string>>();
                        foreach (var rec in reccEvents)
                        {
                            var exceptionList = tasks.Where(x => x.EventId.Contains(rec.EventId + "_")).Select(y => y.EventId.Replace(rec.EventId + "_", "")).ToList();
                            try
                            {
                                test.Add(rec.EventId, exceptionList);
                            }
                            catch { }
                        }

                        foreach (var item in tasks)
                        {
                            if (!string.IsNullOrEmpty(item.ColorId))
                            {
                                var coloritem = colmaster.Where(m => m.Row_Id == int.Parse(item.ColorId)).FirstOrDefault();
                                item.ColorId = coloritem.Row_Id.ToString();
                                ViewBag.Color = coloritem.Color;
                            }
                            else
                            {
                                item.ColorId = GetUsercalenderColor(item.CalendarId.Value, usercalenderlst, colmaster);
                                var coloritem = colmaster.Where(m => m.Row_Id == int.Parse(item.ColorId)).FirstOrDefault();
                                ViewBag.Color = coloritem.Color;
                            }
                            var eventObj = new CalEventViewModel();
                            if (item.StartDate.Value.Year.ToString() != "1900" && !item.Recurrence.StartsWith("~EXDATE"))
                            {
                                eventObj.EventId = item.EventId;
                                eventObj.Title = item.Title;
                                eventObj.Start = TimeZoneInfo.ConvertTimeToUtc((DateTime)item.StartDate);
                                eventObj.End = TimeZoneInfo.ConvertTimeToUtc((DateTime)item.EndDate);

                                DateTime endTime = DateTime.Now.AddSeconds(75);
                                TimeSpan span = eventObj.End.Subtract(eventObj.Start);

                                string timeSlot = string.Format("{0:D2} hours :{1:D2}minutes",
                                span.Hours,
                                span.Minutes

                                );

                                DateTime dtstart = (DateTime)item.StartDate;
                                DateTime dtEnd = (DateTime)item.EndDate;

                                string strdtStart = dtstart.ToString("dd/MM/yyyy");
                                string strdtEnd = dtEnd.ToString("dd/MM/yyyy");

                                eventObj.TooltipDescription = "Start Date: " + dtstart.ToString() + "\nEnd Date: " + dtEnd.ToString() + "\nDuration: " + timeSlot;
                                eventObj.Description = item.Description;

                                if (!string.IsNullOrEmpty(item.Recurrence))
                                {
                                    eventObj.RecurrenceRule = item.Recurrence.Replace("~RRULE:", string.Empty);
                                }

                                string exception = string.Empty;
                                if (preExceptionList.Keys.Contains(eventObj.EventId))
                                    exception = preExceptionList[eventObj.EventId];
                                if (test.Keys.Contains(eventObj.EventId))
                                {

                                    foreach (string exc in test[eventObj.EventId])
                                    {

                                        if (exception == string.Empty)
                                        {
                                            if (!exception.Contains(exc))
                                                exception = exc;
                                        }
                                        else
                                        {
                                            if (!exception.Contains(exc))
                                                exception = exception + ";" + exc;
                                        }
                                    }
                                    if (!preExceptionList.Keys.Contains(eventObj.EventId) && !string.IsNullOrEmpty(exception))
                                    {
                                        var EventException = new EventException { EventId = eventObj.EventId, Exception = exception };
                                        lstException.Add(EventException);

                                    }
                                    else if (preExceptionList.Keys.Contains(eventObj.EventId))
                                    {
                                        if (preExceptionList[eventObj.EventId] != exception)
                                        {
                                            var EventExceptionUpdate = getAllEventException.FirstOrDefault(x => x.EventId == eventObj.EventId);

                                            EventExceptionUpdate.Exception = exception;
                                            lstException.Add(EventExceptionUpdate);
                                            //  OrderMangtDB.EventExceptions.Add(EventExceptionUpdate);
                                        }
                                    }

                                    eventObj.RecurrenceException = exception;
                                }
                                eventObj.EventId = item.EventId;
                                eventObj.RecurrenceID = item.RecurrenceID;
                                eventObj.CalendarId = item.CalendarId;
                                eventObj.CalenderUser = item.CalendarId;
                                eventObj.Organizer = item.Organizer;
                                eventObj.Location = item.Location;
                                eventObj.Status = item.Status;
                                eventObj.Creator = item.Creator;
                                eventObj.ColorId = item.ColorId;
                                eventObj.EventColorid = int.Parse(item.ColorId);
                                eventObj.Color = ViewBag.Color;
                                eventObj.Description = item.Description;
                                eventObj.DeleteRecurrenceEvent = item.EventId;
                                if (item.IsAllDay != null)
                                    eventObj.IsAllDay = item.IsAllDay.Value;

                                events.Add(eventObj);
                            }
                        }
                    }

                    lock ("EventException")
                    {
                        _scheduler.AddOrUpdateException(lstException);
                    }

                    var temp = events as IEnumerable<CalEventViewModel>;
                    JsonResult jsonResult = Json(temp.ToDataSourceResult(request));
                    jsonResult.MaxJsonLength = Int32.MaxValue;
                    return jsonResult;
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(chkselected))
                {
                    if (chkselected.EndsWith(","))
                    {
                        chkselected = chkselected.Remove(chkselected.Length - 1);
                    }

                    List<int> userIds = new List<int>(Array.ConvertAll(chkselected.Split(','), int.Parse));

                    if (userIds != null && userIds.Count > 0)
                    {
                        end = end.AddDays(1);

                        var tasks = _scheduler.GetAllEventByUserIdAndDate(userIds, start, end);
                        var preExceptionList = _scheduler.GetEventExceptions();
                        var getAllEventException = _scheduler.GetAllEventException();
                        var colmaster = _scheduler.GetAllColor();
                        var usercalenderlst = _scheduler.GetAllCalendarUser();
                        if (tasks.ToList().Count > 0)
                        {
                            var reccEvents = tasks.Where(x => !string.IsNullOrEmpty(x.Recurrence)).ToList();

                            Dictionary<string, List<string>> test = new Dictionary<string, List<string>>();
                            foreach (var rec in reccEvents)
                            {
                                var exceptionList = tasks.Where(x => x.EventId.Contains(rec.EventId + "_")).Select(y => y.EventId.Replace(rec.EventId + "_", "")).ToList();
                                test.Add(rec.EventId, exceptionList);
                            }

                            foreach (var item in tasks)
                            {
                                if (!string.IsNullOrEmpty(item.ColorId))
                                {
                                    var coloritem = colmaster.Where(m => m.Row_Id == int.Parse(item.ColorId)).FirstOrDefault();
                                    item.ColorId = coloritem.Row_Id.ToString();
                                    ViewBag.Color = coloritem.Color;
                                }
                                else
                                {
                                    item.ColorId = GetUsercalenderColor(item.CalendarId.Value, usercalenderlst, colmaster);
                                    var coloritem = colmaster.Where(m => m.Row_Id == int.Parse(item.ColorId)).FirstOrDefault();
                                    ViewBag.Color = coloritem.Color;

                                }
                                var eventObj = new CalEventViewModel();
                                if (item.StartDate.Value.Year.ToString() != "1900" && !item.Recurrence.StartsWith("~EXDATE"))
                                {
                                    eventObj.EventId = item.EventId;
                                    eventObj.Title = item.Title;

                                    eventObj.Start = TimeZoneInfo.ConvertTimeToUtc((DateTime)item.StartDate);

                                    //.ToUniversalTime();// DateTime.SpecifyKind(DateTime.Parse(item.StartDate.ToString()), DateTimeKind.Utc);
                                    eventObj.End = TimeZoneInfo.ConvertTimeToUtc((DateTime)item.EndDate);

                                    DateTime endTime = DateTime.Now.AddSeconds(75);
                                    TimeSpan span = eventObj.End.Subtract(eventObj.Start);

                                    //string timeSlot = string.Format("{0:D2} hours :{1:D2}minutes :{2:D2}seconds",
                                    //span.Hours,
                                    //span.Minutes,
                                    //span.Seconds
                                    //);

                                    string timeSlot = string.Format("{0:D2} hours :{1:D2}minutes",
                                    span.Hours,
                                    span.Minutes

                                    );

                                    DateTime dtstart = (DateTime)item.StartDate;
                                    DateTime dtEnd = (DateTime)item.EndDate;

                                    string strdtStart = dtstart.ToString("dd/MM/yyyy");
                                    string strdtEnd = dtEnd.ToString("dd/MM/yyyy");

                                    eventObj.TooltipDescription = "Start Date: " + dtstart.ToString() + "\nEnd Date: " + dtEnd.ToString() + "\nDuration: " + timeSlot;

                                    //DateTime.Parse(item.StartDate.ToString()).ToUniversalTime();// DateTime.SpecifyKind(DateTime.Parse(item.EndDate.ToString()), DateTimeKind.Utc);
                                    eventObj.Description = item.Description;

                                    //if (item.StartDate.Value.ToString("HH:mm:ss") == "00:00:00"  && item.EndDate.Value.ToString("HH:mm:ss") == "00:00:00")
                                    //{
                                    //    eventObj.IsAllDay = true;
                                    //    eventObj.End = eventObj.End.AddDays(-1);
                                    //}
                                    //else
                                    //{
                                    //    eventObj.IsAllDay = false;
                                    //}

                                    if (!string.IsNullOrEmpty(item.Recurrence))
                                    {

                                        eventObj.RecurrenceRule = item.Recurrence.Replace("~RRULE:", string.Empty);
                                    }

                                    string exception = string.Empty;
                                    if (preExceptionList.Keys.Contains(eventObj.EventId))
                                        exception = preExceptionList[eventObj.EventId];
                                    if (test.Keys.Contains(eventObj.EventId))
                                    {

                                        foreach (string exc in test[eventObj.EventId])
                                        {

                                            if (exception == string.Empty)
                                            {
                                                if (!exception.Contains(exc))
                                                    exception = exc;
                                            }
                                            else
                                            {
                                                if (!exception.Contains(exc))
                                                    exception = exception + ";" + exc;
                                            }
                                        }
                                        if (!preExceptionList.Keys.Contains(eventObj.EventId) && !string.IsNullOrEmpty(exception))
                                        {
                                            var EventException = new EventException { EventId = eventObj.EventId, Exception = exception };
                                            lstException.Add(EventException);

                                        }
                                        else if (preExceptionList.Keys.Contains(eventObj.EventId))
                                        {
                                            if (preExceptionList[eventObj.EventId] != exception)
                                            {
                                                var EventExceptionUpdate = getAllEventException.FirstOrDefault(x => x.EventId == eventObj.EventId);

                                                EventExceptionUpdate.Exception = exception;
                                                lstException.Add(EventExceptionUpdate);
                                                //  OrderMangtDB.EventExceptions.Add(EventExceptionUpdate);
                                            }
                                        }

                                        eventObj.RecurrenceException = exception;
                                    }
                                    eventObj.EventId = item.EventId;
                                    eventObj.RecurrenceID = item.RecurrenceID;
                                    eventObj.CalendarId = item.CalendarId;
                                    eventObj.CalenderUser = item.CalendarId;
                                    eventObj.Organizer = item.Organizer;
                                    eventObj.Location = item.Location;
                                    eventObj.Status = item.Status;
                                    eventObj.Creator = item.Creator;
                                    eventObj.ColorId = item.ColorId;
                                    eventObj.EventColorid = int.Parse(item.ColorId);
                                    eventObj.Color = ViewBag.Color;
                                    eventObj.Description = item.Description;
                                    eventObj.DeleteRecurrenceEvent = item.EventId;
                                    if (item.IsAllDay != null)
                                        eventObj.IsAllDay = item.IsAllDay.Value;

                                    events.Add(eventObj);
                                }
                            }
                        }

                        lock ("EventException")
                        {
                            _scheduler.AddOrUpdateException(lstException);
                        }

                        var temp = events as IEnumerable<CalEventViewModel>;
                        JsonResult jsonResult = Json(temp.ToDataSourceResult(request));
                        jsonResult.MaxJsonLength = Int32.MaxValue;
                        return jsonResult;
                    }

                }
            }
            return null;
        }
Ejemplo n.º 3
0
        public virtual JsonResult Event_Create([DataSourceRequest] DataSourceRequest request, CalEventViewModel eventViewModel, List<int> userIds)
        {
            try
            {

                if (ModelState.IsValid)
                {
                    using (var OrderMangtDB = new OrderMgntEntities())
                    {
                        var entity = new Event
                        {
                            Title = eventViewModel.Title,
                            //StartDate = DateTime.SpecifyKind(eventViewModel.Start, DateTimeKind.Local),
                            //EndDate = DateTime.SpecifyKind(eventViewModel.End, DateTimeKind.Local),
                            StartDate = eventViewModel.Start,//StartDateParam,
                            EndDate = eventViewModel.End,
                            Description = eventViewModel.Description,
                            Recurrence = eventViewModel.RecurrenceRule,
                            RecurrenceID = eventViewModel.RecurrenceID,
                            Kind = "calendar#event",
                            IsAllDay = eventViewModel.IsAllDay,
                            CalendarId = eventViewModel.CalenderUser,
                            Organizer = eventViewModel.Organizer,
                            Creator = eventViewModel.Creator,
                            Updated = DateTime.Today,
                            Location = eventViewModel.Location,
                            ColorId = eventViewModel.ColorId
                        };

                        var objGoogleCal = new GoogleServiceMethodCalls();
                        string returnedEventid = string.Empty;
                        int fromCalId;
                        string calName = string.Empty;
                        int orgId;
                        string StagingCalendar = string.Empty;
                        if (eventViewModel.Row_Id != 0)
                        {
                            fromCalId = (int)OrderMangtDB.Events.First(x => x.Row_Id == eventViewModel.Row_Id).CalendarId;
                            calName = OrderMangtDB.Calendars.FirstOrDefault(c => c.Row_Id == fromCalId).Name;
                            orgId = (int)UserManager.Current().OrgId;
                            StagingCalendar = OrderMangtDB.Calendars.FirstOrDefault(x => (x.Org_Id != null && x.Org_Id == orgId) && (x.StagingCalendar != null && x.StagingCalendar == true)).Name;
                        }
                        if (eventViewModel.Isdrag && calName != StagingCalendar && eventViewModel.Row_Id != 0)
                        {
                            string creator = string.Empty;
                            string organizer = string.Empty;
                            string eventId = eventViewModel.GoogleEventid;
                            int eventRowId = eventViewModel.Row_Id;
                            string destinationCalendar = eventViewModel.CalenderUser.ToString();
                            var calendars = OrderMangtDB.Calendars.SingleOrDefault(m => m.Row_Id == eventViewModel.CalenderUser);
                            var fromCalendarId = OrderMangtDB.Events.First(m => m.Row_Id == eventRowId).CalendarId;
                            var fromCalendar = OrderMangtDB.Calendars.SingleOrDefault(m => m.Row_Id == fromCalendarId);
                            if (calendars != null)
                            {
                                if (entity.StartDate != null && entity.EndDate != null)
                                {
                                    Logger("MoveEvent called within Create block Called" + " || " + entity.Title);

                                    int OldEventRowId = Convert.ToInt32(_scheduler.GetEventRowId(eventId).FirstOrDefault().EventRow_id);

                                    returnedEventid = objGoogleCal.MoveEvent(entity.StartDate.Value, entity.EndDate.Value, creator,
                                           organizer,
                                           entity.Location, entity.Title, eventId, calendars.Name, fromCalendar.Name, (int)entity.Sequence, entity.Description ?? string.Empty, entity.Recurrence ?? string.Empty, entity.IsAllDay ?? false, entity.ColorId ?? string.Empty);
                                    eventViewModel.EventId = returnedEventid;

                                    int LoggedInUserId = (int)UserManager.Current().Row_Id;
                                    DBLogger(returnedEventid, entity.Title, "MoveEvent", LoggedInUserId, fromCalendar.Name, calendars.Name);

                                    _scheduler.UpdateJobEvents(returnedEventid, calendars.Name, fromCalendar.Name, OldEventRowId);///UpdateJobEvents
                                    Logger("UpdateJobEvents Called - " + "eventId: " + returnedEventid + " Source calendar Name : " + fromCalendar.Name + " Destination calendar Name : " + calendars.Name);                                                           ///

                                    LoggedInUserId=   (int)UserManager.Current().Row_Id;
                                    DBLogger(returnedEventid, entity.Title, "MoveEvent", LoggedInUserId, fromCalendar.Name, calendars.Name);

                                    ThrowCustomExc(returnedEventid);

                                    Logger("MoveEvent end within Create block Called");
                                }
                                // objGoogleCal.UpdateEvent(entity.StartDate.Value, entity.EndDate.Value, creator, organizer, entity.Location, entity.Title, eventId, calendars.Name);
                            }

                        }
                        else if (!string.IsNullOrEmpty(eventViewModel.RecurrenceID))
                        {
                            var evnt = OrderMangtDB.Events.First(x => x.EventId == eventViewModel.RecurrenceID && x.Status != "Cancelled");
                            var cal = OrderMangtDB.Calendars.First(x => x.Row_Id == evnt.CalendarId).Name;
                            string colorid = string.Empty;
                            if (eventViewModel.EventColorid.HasValue)
                            {
                                if (eventViewModel.EventColorid.Value <= 11)
                                    colorid = eventViewModel.EventColorid.ToString();
                            }
                            else
                            {
                                if (eventViewModel.CalenderUser != null)
                                {
                                    // colorid = GetUsercalenderColor(eventViewModel.CalenderUser.Value);
                                    colorid = string.Empty;
                                }
                            }
                            entity.EventId = eventViewModel.RecurrenceID;
                            // entity.Sequence = 0;

                            int Sequenceid = (int)OrderMangtDB.Events.First(x => x.EventId == eventViewModel.RecurrenceID).Sequence;
                            Sequenceid++;
                            entity.Sequence = Sequenceid; // != 0 ? Sequenceid: Sequenceid + 1;

                            Logger("UpdateEventInstance called within Create block Called" + " || " + entity.Title);

                            //var startDate = (DateTime)entity.StartDate;

                            //  if (startDate.TimeOfDay.Minutes < 15 && startDate.TimeOfDay.Minutes > 0)
                            //            {
                            //                startDate = new DateTime(startDate.Year, startDate.Month, startDate.Day, startDate.Hour, 00, 00);
                            //            }

                            var returnedEventId = objGoogleCal.UpdateEventInstance((DateTime)entity.StartDate, (DateTime)entity.EndDate, string.Empty, entity.Organizer, entity.Location, entity.Title, entity.EventId, cal, (int)entity.Sequence, entity.Description ?? string.Empty, entity.Recurrence ?? string.Empty, entity.IsAllDay ?? false, colorid ?? entity.ColorId);

                            int LoggedInUserId = (int)UserManager.Current().Row_Id;
                            DBLogger(returnedEventId, entity.Title, "Update Event", LoggedInUserId, cal, cal);

                            // string retUpdateEventId = returnedEventId;

                            ThrowCustomExc(returnedEventId);

                            Logger("UpdateEventInstance end within Create block Called");
                        }
                        else
                        {
                            string colorid = string.Empty;
                            if (eventViewModel.EventColorid.HasValue)
                            {
                                if (eventViewModel.EventColorid.Value < 12) // we only need to pass top 11 clolor while create update
                                {
                                    colorid = eventViewModel.EventColorid.ToString();
                                }
                            }
                            else
                            {
                                if (!string.IsNullOrEmpty(eventViewModel.Color))
                                {
                                    //  colorid = eventViewModel.ColorId,

                                    colorid = OrderMangtDB.ColorMasters.First(x => x.Color == eventViewModel.Color).Row_Id.ToString();
                                }
                                else
                                {
                                    colorid = string.Empty;
                                }

                                //if (eventViewModel.CalenderUser != null)
                                //{
                                //    colorid = GetUsercalenderColor(eventViewModel.CalenderUser.Value);
                                //}
                                //colorid = string.Empty;
                            }
                            var calendars = OrderMangtDB.Calendars.SingleOrDefault(m => m.Row_Id == eventViewModel.CalenderUser);

                            Logger("UpdateEventInstance end within Create block Called" + " || " + entity.Title);

                            returnedEventid = objGoogleCal.CreateEvent(entity.Title, entity.Location, string.Empty,
                                entity.StartDate.Value, entity.EndDate.Value, string.Empty, entity.Description,
                                string.Empty, string.Empty, colorid, calendars.Name, entity.Description ?? string.Empty, entity.Recurrence ?? string.Empty, entity.IsAllDay ?? false);

                            string strreturnedEventid = returnedEventid;

                            string[] parts = strreturnedEventid.Split(',');

                            string EventidfrmGoogle = string.Empty; string seqId = string.Empty;
                            if ((parts[0] != null && parts[0].Length > 0))
                            {
                                EventidfrmGoogle = (parts[0].ToString());
                                seqId = (parts[1].ToString());
                            }

                            int LoggedInUserId = (int)UserManager.Current().Row_Id;
                            DBLogger(EventidfrmGoogle, entity.Title, "Create Event", LoggedInUserId, calendars.Name, calendars.Name);

                            Logger("CreateEvent end within Create block Called");

                            if (returnedEventid != string.Empty)
                            {
                                var retValues = returnedEventid.Split(',');
                                eventViewModel.EventId = retValues[0];
                                eventViewModel.Sequence = Convert.ToInt32(retValues[1]);
                                ThrowCustomExc(retValues[0]);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                #region For Error

                string Error = ErrorMsg;

                if (!string.IsNullOrEmpty(ErrorMsg))
                {

                    switch (Error)
                    {
                        case "CustomError400":
                            return Json(new DataSourceResult
                      {
                          // Errors = "You cannot change the organizer of an instance."
                          Errors = "CustomError400"
                      });

                        case "CustomError401":
                            return Json(new DataSourceResult
                   {
                       //Errors = "You cannot turn an instance of a recurring event into a recurring event itself."
                       Errors = "CustomError401"
                   });

                        case "Null_Event":
                            return Json(new DataSourceResult
                   {
                       Errors = "Null_Event"
                   });

                        //default:
                        //         Logger(ex.InnerException.Message);
                        //         return Json(new DataSourceResult
                        //    {

                        //        Errors = string.Empty
                        //    });
                    }
                }
                else
                {
                    return Json(new DataSourceResult
                    {
                        Errors = ""
                    });
                }
                #endregion

            }

            // Return the inserted task. The scheduler needs the generated TaskID. Also return any validation errors.

            //List<int> userid = new List<int> { };
            //Event_Read(request, "", DateTime.Now, DateTime.Now);

            return Json(new[] { eventViewModel }.ToDataSourceResult(request, ModelState));
        }
Ejemplo n.º 4
0
        public virtual JsonResult print([DataSourceRequest] DataSourceRequest request, CalEventViewModel eventViewModel)
        {
            try
            {
                string returnedEventId = string.Empty;
                if (string.IsNullOrEmpty(eventViewModel.RecurrenceException))
                {
                    if (ModelState.IsValid)
                    {
                        var tasksEventCalendar = _scheduler.GetAllEventByEventID(eventViewModel.EventId);
                        var CalendarsByRowId = _scheduler.GetCalendarsByRowId(eventViewModel.CalendarId);

                        //  var eventCalendar = OrderMangtDB.Events.First(x => x.EventId == eventViewModel.EventId).CalendarId;
                        var eventCalendar = tasksEventCalendar.First(x => x.EventId == eventViewModel.EventId).CalendarId;

                        var entity = tasksEventCalendar.FirstOrDefault(m => m.EventId == eventViewModel.EventId);

                        // Create a new Task entity and set its properties from the posted TaskViewModel
                        if (!string.IsNullOrEmpty(eventViewModel.EventId))
                        {
                            entity.EventId = eventViewModel.EventId;
                        }

                        entity.Title = eventViewModel.Title;
                        //Specify the DateTimeKind to be UTC
                        entity.StartDate = eventViewModel.Start;
                        entity.EndDate = eventViewModel.End;
                        entity.Description = eventViewModel.Description;
                        entity.Recurrence = eventViewModel.RecurrenceRule;
                        entity.RecurrenceID = eventViewModel.RecurrenceID;
                        entity.CalendarId = eventViewModel.CalenderUser != null ? eventViewModel.CalenderUser : entity.CalendarId;
                        entity.Organizer = eventViewModel.Organizer;
                        entity.Kind = "calendar#event";
                        entity.Location = eventViewModel.Location;
                        entity.Updated = DateTime.Today;
                        entity.Sequence = eventViewModel.Sequence == 0 ? entity.Sequence + 1 : 0;
                        // entity.Sequence =  eventViewModel.Sequence;
                        entity.IsAllDay = eventViewModel.IsAllDay;

                        GoogleServiceMethodCalls objGoogleCal = new GoogleServiceMethodCalls();

                        var CalendarsUser = _scheduler.GetCalendarsByRowId(eventViewModel.CalenderUser);

                        var calendars = CalendarsUser.SingleOrDefault(m => m.Row_Id == eventViewModel.CalenderUser);
                        string DestinationCalName = CalendarsUser.SingleOrDefault(m => m.Row_Id == eventViewModel.CalenderUser).Name.ToString();

                        if (eventCalendar != eventViewModel.CalenderUser)
                        {
                            // var fromCalendarId = OrderMangtDB.Events.First(m => m.Row_Id == eventRowId).CalendarId;
                            var fromCalendar = CalendarsByRowId.SingleOrDefault(m => m.Row_Id == eventViewModel.CalendarId);
                            string frmCalName = fromCalendar.Name.ToString();

                            if (entity.StartDate != null && entity.EndDate != null)

                                Logger("MoveEvent within Update block Called" + " || " + entity.Title);

                            int OldEventRowId = Convert.ToInt32(_scheduler.GetEventRowId(eventViewModel.EventId).FirstOrDefault().EventRow_id);

                            returnedEventId = objGoogleCal.MoveEvent(entity.StartDate.Value, entity.EndDate.Value, string.Empty, string.Empty,
                                entity.Location, entity.Title, entity.EventId, DestinationCalName, frmCalName, (int)entity.Sequence, entity.Description ?? string.Empty, entity.Recurrence ?? string.Empty, entity.IsAllDay ?? false, entity.ColorId ?? string.Empty);
                            eventViewModel.EventId = returnedEventId;

                            int LoggedInUserId = (int)UserManager.Current().Row_Id;
                            DBLogger(returnedEventId, entity.Title, "Move Event", LoggedInUserId, frmCalName, DestinationCalName);

                            _scheduler.UpdateJobEvents(returnedEventId, DestinationCalName, frmCalName, OldEventRowId);///UpdateJobEvents
                            ///
                            Logger("UpdateJobEvents Called - " + "eventId: " + returnedEventId + " Source calendar Name : " + frmCalName + " Destination calendar Name : " + DestinationCalName);                                                           ///
                            ///

                            LoggedInUserId = (int)UserManager.Current().Row_Id;
                            DBLogger(returnedEventId, entity.Title, "Move Event", LoggedInUserId, frmCalName, DestinationCalName);

                            ThrowCustomExc(returnedEventId);

                            Logger("MoveEvent end within Update block Called");
                        }
                        else
                        {
                            string colorid = string.Empty;
                            if (eventViewModel.EventColorid.HasValue)
                            {
                                if (eventViewModel.EventColorid.Value <= 11)
                                    colorid = eventViewModel.EventColorid.ToString();
                            }
                            else
                            {
                                if (eventViewModel.CalenderUser != null)
                                {
                                    // colorid = GetUsercalenderColor(eventViewModel.CalenderUser.Value);
                                    colorid = string.Empty;
                                }
                            }

                            Logger("UpdateEvent called within Update block " + " || " + entity.Title);

                            returnedEventId = objGoogleCal.UpdateEvent((DateTime)entity.StartDate, (DateTime)entity.EndDate, string.Empty, entity.Organizer, entity.Location, entity.Title, entity.EventId, calendars.Name, (int)entity.Sequence, entity.Description ?? string.Empty, entity.Recurrence ?? string.Empty, entity.IsAllDay ?? false, colorid ?? entity.ColorId);

                            int LoggedInUserId = (int)UserManager.Current().Row_Id;
                            DBLogger(returnedEventId, entity.Title, "Update Event", LoggedInUserId, calendars.Name, calendars.Name);

                            ThrowCustomExc(returnedEventId);

                            eventViewModel.EventId = returnedEventId;

                            Logger("UpdateEvent end within Update block ");
                        }
                    }
                }

                // Return the updated task. Also return any validation errors.
                return Json(new[] { eventViewModel }.ToDataSourceResult(request, ModelState));
            }
            catch (Exception ex)
            {
                #region For Error

                string Error = ErrorMsg;

                if (!string.IsNullOrEmpty(ErrorMsg))
                {

                    switch (Error)
                    {
                        case "CustomError400":
                            return Json(new DataSourceResult
                            {
                                // Errors = "You cannot change the organizer of an instance."
                                Errors = "CustomError400"
                            });

                        case "CustomError401":
                            return Json(new DataSourceResult
                            {
                                //Errors = "You cannot turn an instance of a recurring event into a recurring event itself."
                                Errors = "CustomError401"
                            });

                        case "Null_Event":
                            return Json(new DataSourceResult
                            {
                                Errors = "Null_Event"
                            });

                        default:
                            return Json(new DataSourceResult
                            {
                                Errors = ""
                            });
                    }
                }
                else
                {
                    return Json(new DataSourceResult
                    {
                        Errors = ""
                    });
                }
                #endregion For Error

            }
        }
Ejemplo n.º 5
0
        public ActionResult Jobs_Read([DataSourceRequest] DataSourceRequest request)
        {
            var colormaster = _scheduler.GetAllColor();
            var usercalenderlst = _scheduler.GetAllCalendarUser();
            var calenderlist = _scheduler.GetAllCalendars();

            var orgId = UserManager.Current().OrgId;

            var StagingCalendar = calenderlist.FirstOrDefault(x => (x.Org_Id != null && x.Org_Id == orgId) && (x.StagingCalendar != null && x.StagingCalendar == true));

            if (StagingCalendar != null)
            {
                DateTime dtbeforeOneMon = DateTime.Now.AddDays(-31);
                var unScheduledjoblist = _scheduler.GetUnScheduledjoblist(StagingCalendar.Row_Id, dtbeforeOneMon);

                if (unScheduledjoblist.Count > 0)
                {
                    IList<CalEventViewModel> events = new List<CalEventViewModel>();

                    foreach (var item in unScheduledjoblist)
                    {
                        if (!string.IsNullOrEmpty(item.ColorId))
                        {
                            var coloritem = colormaster.Where(m => m.Row_Id == int.Parse(item.ColorId)).FirstOrDefault();
                            item.ColorId = coloritem.Row_Id.ToString();
                            ViewBag.Color = coloritem.Color;
                        }
                        else
                        {
                            item.ColorId = GetUsercalenderColor(item.CalendarId.Value, usercalenderlst, colormaster);
                            var coloritem = colormaster.Where(m => m.Row_Id == int.Parse(item.ColorId)).FirstOrDefault();
                            ViewBag.Color = coloritem.Color;

                        }

                        var eventObj = new CalEventViewModel();
                        eventObj.Row_Id = item.Row_Id;
                        eventObj.EventId = item.EventId;
                        eventObj.Title = item.Title;
                        //Specify the DateTimeKind to be UTC
                        eventObj.Start = DateTime.Today;
                        eventObj.End = DateTime.Today.AddHours(1);
                        eventObj.Description = item.Description;
                        eventObj.IsAllDay = false;
                        eventObj.RecurrenceException = null;
                        eventObj.RecurrenceID = null;
                        eventObj.UnscheduledJobs = item.Title;
                        eventObj.Location = item.Location;
                        eventObj.ColorId = item.ColorId;
                        eventObj.Color = ViewBag.Color; // ColorMasterColor.FirstOrDefault(cm => cm.Row_Id == Convert.ToInt32(item.ColorId == "" ? GetUsercalenderColor(item.CalendarId.Value) : item.ColorId)).Color; // Setting default color code 0  //"#DC2127";
                        //eventObj.UnScheduleToolTip = "Title: "+ item.Title + "\nDescription: " + item.Description + "\nRequired Date: " + item.StartDate.Value.ToShortDateString() + "\nLocation: " + item.Location;
                        eventObj.UnScheduleToolTip = "Title: " + item.Title + "\nLocation: " + item.Location + "\nDescription: " + item.Description;
                        events.Add(eventObj);
                    }

                    var temp = events as IEnumerable<CalEventViewModel>;
                    JsonResult jsonResult = Json(temp.ToDataSourceResult(request));
                    jsonResult.MaxJsonLength = Int32.MaxValue;
                    return jsonResult;
                }
            }
            //  }

            return null;
        }
Ejemplo n.º 6
0
        public ActionResult Jobs_Destroy([DataSourceRequest] DataSourceRequest request, CalEventViewModel eventViewModel)
        {
            int fromCalendarId = 0;
            string fromCalendar = string.Empty;
            int eventRowId = eventViewModel.Row_Id;
            using (var OrderMangtDB = new OrderMgntEntities())
            {
                fromCalendarId = (int)OrderMangtDB.Events.First(m => m.Row_Id == eventRowId).CalendarId;
                fromCalendar = OrderMangtDB.Calendars.SingleOrDefault(m => m.Row_Id == fromCalendarId).Name;
            }
            try
            {

                if (!string.IsNullOrEmpty(eventViewModel.EventId))
                {
                    DeleteEvent(eventViewModel.EventId, fromCalendar, fromCalendarId);
                }
                else if (!string.IsNullOrEmpty(eventViewModel.GoogleEventid))
                {
                    DeleteEvent(eventViewModel.GoogleEventid, fromCalendar, fromCalendarId);
                }
            }
            catch (Exception ex)
            {

                string msg = ex.Message;
            }

            //}
            return Json(new[] { eventViewModel }.ToDataSourceResult(request, ModelState));
        }
Ejemplo n.º 7
0
        public static void UpdateEvent(CalEventViewModel eventViewModel, string eventId)
        {
            SetCalendar();

            Event evnt = new Event();
            evnt.Start = new EventDateTime
            {
                DateTime = eventViewModel.Start,
                TimeZone = "Etc/UTC"
            };
            evnt.End = new EventDateTime
            {
                DateTime = eventViewModel.End,
                TimeZone = "Etc/UTC"
            };

            evnt.Created = DateTime.Today;
            evnt.Creator = new Event.CreatorData
            {
                DisplayName = eventViewModel.Creator
            };

            evnt.Organizer = new Event.OrganizerData
            {
                DisplayName = eventViewModel.Organizer,
            };
            evnt.Location = eventViewModel.Location;

            //evnt.Description = "SalesContact : " + SalesContact + Environment.NewLine + Environment.NewLine + "Required On :" + Convert.ToDateTime(RequiredDate).ToShortDateString() + Environment.NewLine + Environment.NewLine + "Product Description :" + ProductDescription + Environment.NewLine + Environment.NewLine + "Supplier Instructions :" + Comments.Replace("Supplier Instructions", "") + Environment.NewLine + Environment.NewLine + "Order Item (Please donot delete or update OrderItemId) :" + OrderId;
            evnt.Summary = eventViewModel.Title;
            evnt.Description = eventViewModel.Title;
            //evnt.Id = eventViewModel.EventId;
            evnt.Location = eventViewModel.Location;
            service.Events.Update(evnt, "*****@*****.**", eventId).Execute();
        }