コード例 #1
0
        public ApiResult <string> tousave(int classid, string ids, int type)
        {
            ApiResult <string> result = new ApiResult <string>();

            try
            {
                var dbh  = DbContext.Get();
                var aids = dbh.Db.Queryable <UserInfo>().Select(ii => new { ii.id, ii.tel }).In("id", mUtils.idsToList(ids)).ToList();

                if (type == 1)
                {
                    //私教
                    foreach (var item in aids)
                    {
                        if (dbh.GetEntityDB <PtOrder>().Count(ii => ii.ptId == classid && ii.userId == item.id) == 0)
                        {
                            PtOrder yo = new PtOrder();
                            yo.create_at = DateTime.Now;
                            yo.ptId      = classid;
                            yo.userId    = item.id;
                            yo.tel       = item.tel;
                            yo.canceled  = false;
                            dbh.Db.Insertable(yo).ExecuteCommand();
                        }
                    }
                }
                else
                {
                    foreach (var item in aids)
                    {
                        if (dbh.GetEntityDB <YogaOrder>().Count(ii => ii.classId == classid && ii.userId == item.id) == 0)
                        {
                            YogaOrder yo = new YogaOrder();
                            yo.create_at = DateTime.Now;
                            yo.classId   = classid;
                            yo.userId    = item.id;
                            yo.tel       = item.tel;
                            yo.canceled  = false;
                            dbh.Db.Insertable(yo).ExecuteCommand();
                        }
                    }
                }
                result.ok = true;
            }
            catch (Exception ex)
            {
                result.ok  = false;
                result.msg = ex.Message;
            }
            return(result);
        }
コード例 #2
0
        public IActionResult Save(int id)
        {
            var      userid = User.FindFirst(ClaimTypes.Sid).Value.AsInt();
            var      dbh    = DbContext.Get();
            UserInfo user   = dbh.Db.Queryable <UserInfo>().InSingle(userid);

            if (user == null)
            {
                return(ShowErrorPage("登录已失效"));
            }
            var pts = dbh.Db.Queryable <PTSchedule>().First(ii => ii.id == id);

            if (pts == null)
            {
                return(ShowErrorPage("无效id"));
            }
            if (pts.kyyzs <= pts.yysl)
            {
                return(ShowErrorPage("私教已约满"));
            }


            if (dbh.Db.Queryable <PtOrder>().Count(ii => ii.userId == userid && ii.ptId == id) > 0)
            {
                return(ShowErrorPage("已预约过相同日期"));
            }
            PtOrder sco = new PtOrder();

            sco.create_at = DateTime.Now;
            sco.tel       = user.tel;
            sco.ptId      = id;
            sco.userId    = userid;
            sco.canceled  = false;
            dbh.Db.Insertable(sco).ExecuteCommand();
            pts.yysl++;
            dbh.Db.Updateable(pts).UpdateColumns(ii => ii.yysl).ExecuteCommand();
            return(View());
        }