Example #1
0
        public int Delete(AgendaParams obj)
        {
            CommonService commonService = new CommonService();
            Agenda        agenda        = GetDetail(obj.ID);

            // 删除Schedule任务计划
            commonService.GetDBContext <Schedule>().DeleteById(agenda.id);
            // 删除AgendaTarget 成员
            commonService.GetDBContext <AgendaTarget>().Delete((t) => t.agendaid == obj.ID);

            return(repository.Delete(agenda));
        }
Example #2
0
 /// <summary>
 /// 查询资源
 /// </summary>
 /// <param name="userid"></param>
 /// <param name="filter"></param>
 /// <returns></returns>
 public IEnumerable <AgendaView> GetList(AgendaParams agendaParams)
 {
     // TODO 获取机构下信息
     return(db.Queryable <Agenda, Schedule, Metadata, KTResource>((a, s, m, r) => new object[] {
         JoinType.Left, a.scheduleid == s.scheduleid,
         JoinType.Left, a.typeid == m.id,
         JoinType.Left, a.authorid == r.id,
     })
            .Where((a, s, m, r) => a.authorid == agendaParams.userID)
            .WhereIF(agendaParams.fromTime != null && agendaParams.toTime != null, (a, s, m, r) => s.endMillis > agendaParams.fromTime && s.startMillis <= agendaParams.toTime)
            .Select <AgendaView>("a.*, floor(UNIX_TIMESTAMP(a.creationDate)*1000) as creationDateunix, floor(UNIX_TIMESTAMP(a.lastModified)*1000) as lastModifiedunix, r.name as authorname, floor(UNIX_TIMESTAMP(s.startx)*1000) as startx, floor(UNIX_TIMESTAMP(s.endx)*1000) as endx, m.id as typeid, m.description as typename")
            .ToList());
 }
        private string GetAgendaList(AgendaParams agendaParams)
        {
            DateTime      focusTime     = agendaParams.focusMillis == null ? DateTime.Now : KTDateTime.ConvertIntDateTime(Convert.ToDouble(agendaParams.focusMillis));
            TimeRangeEnum timeRangeEnum = (TimeRangeEnum)Enum.Parse(typeof(TimeRangeEnum), agendaParams.type.ToUpper());

            DateTime[] arrTimes = KTDateTime.GetTimeRange(timeRangeEnum, focusTime);
            agendaParams.fromTime = arrTimes[0];
            agendaParams.toTime   = arrTimes[1];

            IEnumerable <AgendaView> list = agendaService.GetList(agendaParams);
            XmlDocument doc       = new XmlDocument();
            var         obj       = new { ok = true, events = list };
            string      returnstr = Newtonsoft.Json.JsonConvert.SerializeObject(obj);

            return(returnstr);
        }
Example #4
0
        public IEnumerable <AgendaView> GetList(AgendaParams agendaParams)
        {
            CommonRepository rep = new CommonRepository();
            //var dbset = rep.GetDBContext<AgendaTarget>();

            List <AgendaView> list = (List <AgendaView>)repository.GetList(agendaParams);

            list.ForEach((v) => v.canManage = (v.authorid == agendaParams.userID));

            for (int i = 0; i < list.Count(); i++)
            {
                AgendaView agenda = list.ElementAt(i);
                IEnumerable <AgendaTarget> targets    = repository.GetTargetsList(Convert.ToInt32(agenda.id));
                List <AgendaTarget>        newTargets = new List <AgendaTarget>();
                for (int j = 0; j < targets.Count(); j++)
                {
                    var tar = targets.ElementAt(j);
                    if (!string.IsNullOrWhiteSpace(tar.resAvatarUrl))
                    {
                        //TODO 改成真正的图片地址
                        tar.resAvatarUrl = "https://demo.twproject.com/avatars/015403_9i9nB.jpeg";
                    }
                    else
                    {
                        string resname = tar.resname;
                        if (resname.Length == 2 || resname.Replace(" ", "").Length == 2)
                        {
                            // eg:刘 真,取:刘 真
                            tar.resAvatarUrl = string.Format("/img/svgAvatar?code={0}&fill=hsl%28180%2C70%25%2C80%25%29&stroke=hsl%28180%2C90%25%2C20%25%29"
                                                             , System.Web.HttpUtility.UrlEncode(tar.resname.Replace(" ", ""), System.Text.Encoding.UTF8));
                        }
                        else if (resname.Replace(" ", "").Length == 3)
                        {
                            // eg:刘天真,取:天真
                            tar.resAvatarUrl = string.Format("/img/svgAvatar?code={0}&fill=hsl%28180%2C70%25%2C80%25%29&stroke=hsl%28180%2C90%25%2C20%25%29"
                                                             , System.Web.HttpUtility.UrlEncode(tar.resname.Replace(" ", "").Substring(1, 2), System.Text.Encoding.UTF8));
                        }
                        else if (resname.IndexOf(" ") > 0)
                        {
                            // eg:Jimmy Smith,取:JM
                            string[] arr = resname.Split(' ');
                            string   s   = string.Empty;
                            for (int m = 0; m < arr.Length; m++)
                            {
                                s += arr[m].Substring(0, 1);
                            }
                            tar.resAvatarUrl = string.Format("/img/svgAvatar?code={0}&fill=hsl%28180%2C70%25%2C80%25%29&stroke=hsl%28180%2C90%25%2C20%25%29"
                                                             , System.Web.HttpUtility.UrlEncode(s, System.Text.Encoding.UTF8));
                        }
                        else
                        {
                            tar.resAvatarUrl = string.Format("/img/svgAvatar?code={0}&fill=hsl%28180%2C70%25%2C80%25%29&stroke=hsl%28180%2C90%25%2C20%25%29"
                                                             , System.Web.HttpUtility.UrlEncode(resname, System.Text.Encoding.UTF8));
                        }
                    }

                    newTargets.Add(tar);
                }
                agenda.targets  = newTargets;
                agenda.schedule = repository.GetSchedule(agenda.scheduleid);
                if (agenda.schedule != null)
                {
                    agenda.schedule.type = "period";
                }
            }
            return(list);
        }
        public HttpResponseMessage AgendaAjax()
        {
            IEnumerable <KeyValuePair <string, string> > queryString = Request.GetQueryNameValuePairs();
            AgendaParams agendaParams = KTUtils.GetObjectFromRequest <AgendaParams>(queryString);

            if (agendaParams.CM.ToUpper() == "MICSAVE")
            {
                Schedule schedule = KTUtils.GetObjectFromRequest <Schedule>(queryString);
                schedule.discriminator = "P";
                schedule.startTime     = schedule.startMillis.TimeOfDay.TotalMilliseconds.ObjToInt();
                schedule.duration      = schedule.endMillis.Subtract(schedule.startMillis).TotalMilliseconds;

                IScheduleService scheduleService = new ScheduleService();
                Schedule         resultS         = scheduleService.Insert(schedule);

                // 保存
                string id     = agendaService.Maxid().id.ToString();
                Agenda agenda = KTUtils.GetObjectFromRequest <Agenda>(queryString);
                agenda.id           = id;
                agenda.typeid       = agenda.type.ObjToInt();
                agenda.authorid     = this.UserID.ToString();
                agenda.creator      = this.UserInfo.UserName;
                agenda.lastModifier = this.UserInfo.UserName;
                agenda.creationDate = DateTime.Now;
                agenda.lastModified = DateTime.Now;
                agenda.icalId       = "TW_" + id;
                agenda.exceptions   = string.Empty;
                agenda.scheduleid   = resultS.scheduleid;
                Agenda result = agendaService.Insert(agenda);

                // 写入关联人员
                List <AgendaTarget> listTar = new List <AgendaTarget>();
                string[]            ids     = (agendaParams.WG_IDS ?? "").Split(',');
                for (int i = 0; i < ids.Length; i++)
                {
                    listTar.Add(new AgendaTarget {
                        agendaid = result.id, resid = ids[i]
                    });
                }

                if (listTar.Count > 0)
                {
                    IAgendaTargetService agendaTargetService = new AgendaTargetService();
                    agendaTargetService.Insert(listTar);
                }

                // 查询
                string returnstr = GetAgendaList(agendaParams);
                return(new JsonResult(returnstr));
            }
            else if (agendaParams.CM.ToUpper() == "GETEVENTS")
            {
                // 查询
                agendaParams.userID = this.UserID.ToString();

                // 时间范围计算
                string returnstr = GetAgendaList(agendaParams);
                return(new JsonResult(returnstr));
            }
            else if (agendaParams.CM.ToUpper() == "DELEV")
            {
                // 删除
                agendaService.Delete(agendaParams);

                string returnstr = GetAgendaList(agendaParams);
                return(new JsonResult(returnstr));
            }
            else
            {
                var    obj       = new { ok = true, events = "" };
                string returnstr = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
                return(new JsonResult(returnstr));
            }
        }