Beispiel #1
0
        public JsonResult SaveCalendar(int Id,FormCollection form)
        {
            JsonReturnMessages r = new JsonReturnMessages();
            try
            {
                Calendar data;
                if (Id > 0)
                {
                    data = _service.GetCalendar(Id);       

                }
                else
                {
                    data = new Calendar();
                }
                data.Subject = form["Subject"];
                data.Location = form["Location"];
                data.Description = form["Description"];
                data.IsAllDayEvent = form["IsAllDayEvent"] !="false";
                data.Category = form["colorvalue"];
                string sdate = form["stpartdate"];
                string edate = form["etpartdate"];
                string stime = form["stparttime"];
                string etime = form["etparttime"];
                int clientzone = Convert.ToInt32(form["timezone"]);
                int serverzone = TimeHelper.GetTimeZone();
                var zonediff = serverzone - clientzone;
             
                if (data.IsAllDayEvent)
                {
                    data.StartTime = Convert.ToDateTime(sdate).AddHours(zonediff);
                    data.EndTime = Convert.ToDateTime(edate).AddHours(23).AddMinutes(59).AddSeconds(59).AddHours(zonediff);
                }
                else
                {
                    data.StartTime = Convert.ToDateTime(sdate + " " + stime).AddHours(zonediff);
                    data.EndTime = Convert.ToDateTime(edate + " " + etime).AddHours(zonediff);
                }
                if (data.EndTime <= data.StartTime)
                {
                    throw new Exception(this.Resource("lang,starttimegreatthanendtime"));
                }
                data.CalendarType = 1;
                data.InstanceType = 0;
                data.MasterId = clientzone;
                data.UPAccount = UserId;
                data.UPName = this.Resource("lang,admin");
                data.UPTime = DateTime.Now;

                if (data.Id > 0)
                {
                    _service.UpdateCalendar(data);
                }
                else {
                    _service.AddCalendar(data);
                }
                r.IsSuccess = true;
                r.Msg = this.Resource("lang,successmsg");
            }
            catch (Exception ex)
            {
                r.IsSuccess = false;
                r.Msg = ex.Message;
            }
            return Json(r);
        }
Beispiel #2
0
 public JsonResult QuickUpdatePersonalCal(FormCollection form)
 {
     JsonReturnMessages r = new JsonReturnMessages();
     string Id = form["calendarId"];
     string strStartTime = form["CalendarStartTime"];
     string strEndTime = form["CalendarEndTime"];
     int clientzone = Convert.ToInt32(form["timezone"]);
     int serverzone = TimeHelper.GetTimeZone();
     var zonediff = serverzone - clientzone;
     DateTime st,et;
   
     bool a = DateTime.TryParse(strStartTime, out st);
     bool b = DateTime.TryParse(strEndTime, out et);
     if (!a || !b)
     {
         r.IsSuccess = false;
         r.Msg =this.Resource("lang,notvoliddatetimeformat")+":" + strStartTime;
         return Json(r);
     }
     try
     {
         Calendar c = _service.GetCalendar(Convert.ToInt32(Id));
         c.StartTime = st.AddHours(zonediff);
         c.EndTime = et.AddHours(zonediff);
         c.MasterId = clientzone;
         _service.UpdateCalendar(c);
         r.IsSuccess = true;
         r.Msg = this.Resource("lang,successmsg");
     }
     catch (Exception ex)
     {
         r.IsSuccess = false;
         r.Msg = ex.Message;
     }
     return Json(r);
 }
Beispiel #3
0
 public JsonResult QuickDeletePersonalCal(FormCollection form)
 {
     JsonReturnMessages r = new JsonReturnMessages();
     string id = form["calendarId"];
     if (string.IsNullOrEmpty(id))
     {
         r.IsSuccess = false;
         r.Msg = this.Resource("lang,parameterinvalid","Id");
         return Json(r);
     }
     try
     {
         _service.DeleteCalendar(Convert.ToInt32(id),base.UserId);
         r.IsSuccess = true;
         r.Msg = this.Resource("lang,successmsg");
     }
     catch (Exception ex)
     {
         r.IsSuccess = false;
         r.Msg = ex.Message;
     }
     return Json(r);
 }
Beispiel #4
0
        public JsonResult QuickAddPersonalCal(FormCollection form)
        {
            JsonReturnMessages r = new JsonReturnMessages();
            string subject = form["CalendarTitle"];
            string strStartTime = form["CalendarStartTime"];
            string strEndTime = form["CalendarEndTime"];
            string isallday = form["IsAllDayEvent"];
            int clientzone = Convert.ToInt32(form["timezone"]);
            int serverzone = TimeHelper.GetTimeZone();
            var zonediff = serverzone - clientzone;
            DateTime st;
            DateTime et;           
            
            bool a = DateTime.TryParse(strEndTime, out et);
            bool b = DateTime.TryParse(strStartTime, out st);
            if (!b)
            {
                r.IsSuccess = false;
                r.Msg = this.Resource("lang,notvoliddatetimeformat")+":" + strStartTime;
                return Json(r);
            }
            if (!a)
            {
                r.IsSuccess = false;
                r.Msg = this.Resource("lang,notvoliddatetimeformat")+":" + strEndTime;
                return Json(r);                
            }           

            try
            {
             
                Calendar entity = new Calendar();
                entity.CalendarType = 1;
                entity.InstanceType = 0;
                entity.Subject = subject;
                entity.StartTime = st.AddHours(zonediff);
                entity.EndTime = et.AddHours(zonediff);
                entity.IsAllDayEvent = isallday == "1";
                entity.UPAccount = UserId;
                entity.UPName = this.Resource("lang,admin");
                entity.UPTime = DateTime.Now;
                entity.MasterId = clientzone;
                r.Data = _service.AddCalendar(entity);
                r.IsSuccess = true;
                r.Msg = this.Resource("lang,successmsg");
                 
            }
            catch (Exception ex)
            {
                r.IsSuccess = false;
                r.Msg = ex.Message;
            }
            return Json(r);
        }