Example #1
0
        public void checkIn(string actId, string userId)
        {
            var act = ActDAO.getInstance().getAct(actId);

            if (act == null)
            {
                this.Fail("無此活動");
                return;
            }


            var today = DateTime.UtcNow.AddHours(8).ToString("yyyy-MM-dd"); //轉成UTC+8
            // Check if the user has checked in
            var isCheckIn = CheckInDAO.getInstance().isCheckIn(actId, userId, today);

            if (!isCheckIn)
            {
                //簽到
                CheckInDAO.getInstance().CheckIn(actId, userId, today);
                this.Message = "今日簽到完畢";
            }
            else
            {
                this.Message = "今日已簽到";
            }

            showCheckIn(actId, userId);
        }
Example #2
0
        public void Act_Add([FromBody] CheckInAct act)
        {
            if (act == null)
            {
                this.Fail("查無資料,請再確認");
                return;
            }
            //檢驗參數,有問題會錯誤
            act = Validact(act);
            if (act == null)
            {
                return;
            }

            //確認活動是否重複
            if (ActDAO.getInstance().getAct(act.actId) != null)
            {
                Fail($"活動id:{act.actId}已經設定");
                return;
            }

            act.created_at = DateTime.Now;
            ActDAO.getInstance().createAct(act);

            this.Ok("建立活動成功", act);
        }
Example #3
0
        public void showActs(DateTime?day)
        {
            var chooseDay = DateTime.Now;

            if (day != null)
            {
                chooseDay = (DateTime)day;
            }

            this.Data = ActDAO.getInstance().showActs(chooseDay);
        }
Example #4
0
        public void Act_Query([FromRoute] String actId)
        {
            var result = ActDAO.getInstance().getAct(actId);

            if (result == null)
            {
                this.Fail("查無資料");
            }
            else
            {
                this.Ok("查詢成功", result);
            }
        }
Example #5
0
        public void Act_Remote([FromHeader] String actId, [FromBody] CheckInAct act)
        {
            bool isOK = ActDAO.getInstance().updateAct(actId, act);

            if (isOK)
            {
                this.Ok("更新活動成功");
            }
            else
            {
                this.Fail("更新活動失敗");
            }
        }
Example #6
0
        public void Act_Remote([FromHeader] String actId)
        {
            bool isOK = ActDAO.getInstance().removeAct(actId);

            if (isOK)
            {
                this.Ok("刪除活動成功");
            }
            else
            {
                this.Fail("刪除活動失敗");
            }
        }
Example #7
0
        public void getDateAndCheckOrNotInformation(string actId, string userId)
        {
            var list = new List <CheckInDataBase>();
            var howManyDaysTheUserHasCheckedInConsecutivelyUntilToday = 0;
            var act = ActDAO.getInstance().getAct(actId);

            if (act == null)
            {
                this.Fail("無此活動");
                return;
            }
            var ok_list = CheckInDAO.getInstance().queryCheckIn(actId, userId);

            var pointDate = (DateTime)act.startTime;

            while (pointDate < act.endTime)
            {
                var data    = new CheckInDataBase();
                var day     = pointDate.ToUniversalTime().AddHours(8).ToString("yyyy-MM-dd"); //轉成UTC+8
                var findArr = ok_list.Where <CheckInData>(e => e.checkIn_data == day);
                if (findArr.Count() != 0)
                {
                    data = findArr.ToList <CheckInData>()[0];
                    howManyDaysTheUserHasCheckedInConsecutivelyUntilToday++;
                }
                else
                {
                    data.checkIn_data = day;
                    data.check_or_not = false;
                }

                list.Add(data);

                pointDate = pointDate.AddDays(1);
            }

            var result = new Dictionary <String, Object>();

            result["howManyDaysTheUserHasCheckedInConsecutivelyUntilToday"] = howManyDaysTheUserHasCheckedInConsecutivelyUntilToday;
            result["detail"] = list;

            Ok("查詢成功", result);
        }