Exemplo n.º 1
0
        public async Task <JsonResult> QuickDeletePersonalCal(FormCollection form)
        {
            JsonReturnMessages r  = new JsonReturnMessages();
            string             id = form["calendarId"];

            if (string.IsNullOrEmpty(id))
            {
                r.IsSuccess = false;
                r.Msg       = "参数id无效";
                return(Json(r));
            }
            try
            {
                await _calendarLogic.DeleteAsync(Convert.ToInt32(id));

                r.IsSuccess = true;
                r.Msg       = "操作成功!";
            }
            catch (Exception ex)
            {
                r.IsSuccess = false;
                r.Msg       = ex.Message;
            }
            return(Json(r));
        }
Exemplo n.º 2
0
        public async Task <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       = "错误的时间格式" + ":" + strStartTime;
                return(Json(r));
            }
            if (!a)
            {
                r.IsSuccess = false;
                r.Msg       = "错误的时间格式" + ":" + strEndTime;
                return(Json(r));
            }

            try
            {
                SystemCalendar entity = new SystemCalendar();
                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     = CurrentUser.UserId;
                entity.UPName        = CurrentUser.Name;
                entity.UPTime        = DateTime.Now;
                entity.MasterId      = clientzone;
                r.Data      = (await _calendarLogic.InsertScalarAsync(entity)).Data;
                r.IsSuccess = true;
                r.Msg       = "操作成功!";
            }
            catch (Exception ex)
            {
                r.IsSuccess = false;
                r.Msg       = ex.Message;
            }
            return(Json(r));
        }
Exemplo n.º 3
0
        public async Task <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       = "错误的时间格式" + ":" + strStartTime;
                return(Json(r));
            }
            try
            {
                SystemCalendar c = await _calendarLogic.GetByIdAsync(Convert.ToInt32(id));

                c.StartTime = st.AddHours(zonediff);
                c.EndTime   = et.AddHours(zonediff);
                c.MasterId  = clientzone;
                await _calendarLogic.UpdateAsync(c);

                r.IsSuccess = true;
                r.Msg       = "操作成功!";
            }
            catch (Exception ex)
            {
                r.IsSuccess = false;
                r.Msg       = ex.Message;
            }
            return(Json(r));
        }
Exemplo n.º 4
0
        public async Task <JsonResult> SaveCalendar(int id, FormCollection form)
        {
            JsonReturnMessages r = new JsonReturnMessages();

            try
            {
                SystemCalendar data;
                if (id > 0)
                {
                    data = await _calendarLogic.GetByIdAsync(id);
                }
                else
                {
                    data = new SystemCalendar();
                }
                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("开始时间不能大于结束时间");
                }
                data.CalendarType = 1;
                data.InstanceType = 0;
                data.MasterId     = clientzone;
                data.UPAccount    = CurrentUser.UserId;
                data.UPName       = CurrentUser.Name;
                data.UPTime       = DateTime.Now;

                if (data.Id > 0)
                {
                    await _calendarLogic.UpdateAsync(data);
                }
                else
                {
                    await _calendarLogic.InsertAsync(data);
                }
                r.IsSuccess = true;
                r.Msg       = "操作成功!";
            }
            catch (Exception ex)
            {
                r.IsSuccess = false;
                r.Msg       = ex.Message;
            }
            return(Json(r));
        }