コード例 #1
0
        public async Task <MessageModel <List <AllData> > > Post(string openId, int infoId, int addCount, string type)
        {
            try
            {
                _userServices.GetAdo().BeginTran();

                var data = new MessageModel <List <AllData> >();

                if (addCount != 0)
                {
                    User user = (await _userServices.Query(q => q.OpenId == openId)).FirstOrDefault();

                    if (user != null)
                    {
                        user.Version += 1;

                        InfoDetail infoDetailInitail = (await _infoDetailServices.Query(q => q.InfoId == infoId && q.Count == 0 && q.Type == "日")).FirstOrDefault();

                        if (infoDetailInitail != null)
                        {
                            InfoDetail infoDetail = new InfoDetail()
                            {
                                InfoId = infoId,
                                Type   = type,
                                Count  = addCount,
                                Date   = GetDate(infoDetailInitail.Date.Value, addCount, type)
                            };

                            if (await _userServices.Update(user) && await _infoDetailServices.Add(infoDetail) > 0)
                            {
                                data.success = true;
                            }

                            if (data.success)
                            {
                                data.response = (await userController.Get(openId)).response;
                                data.msg      = "添加成功";
                                _userServices.GetAdo().CommitTran();
                            }
                            else
                            {
                                _userServices.GetAdo().RollbackTran();
                            }
                        }
                    }
                }
                return(data);
            }
            catch (Exception ex)
            {
                _userServices.GetAdo().RollbackTran();
                throw ex;
            }
        }
コード例 #2
0
        //[Route("Update")]
        public async Task <MessageModel <List <AllData> > > Put(string openId, string infoId, string name, DateTime?date)
        {
            try
            {
                _userServices.GetAdo().BeginTran();

                var data = new MessageModel <List <AllData> >();

                if (!string.IsNullOrEmpty(name) || date != null)
                {
                    User user = (await _userServices.Query(q => q.OpenId == openId)).FirstOrDefault();

                    if (user != null)
                    {
                        user.Version += 1;

                        Info info = (await _infoServices.QueryById(infoId));

                        if (info != null)
                        {
                            if (!string.IsNullOrEmpty(name))
                            {
                                info.Name = name;
                            }
                            if (await _userServices.Update(user) && await _infoServices.Update(info))
                            {
                                if (date != null)
                                {
                                    InfoDetail infoDetail = (await _infoDetailServices.Query(q => q.InfoId.ToString() == infoId && q.Count == 0 && q.Type == "日")).FirstOrDefault();

                                    if (infoDetail != null)
                                    {
                                        infoDetail.Date = date;

                                        if (await _infoDetailServices.Update(infoDetail))
                                        {
                                            List <InfoDetail> infoDetails = (await _infoDetailServices.Query(q => q.InfoId.ToString() == infoId && q.Count != 0 && q.Type != "日")).ToList();

                                            if (infoDetails.Count > 0)
                                            {
                                                foreach (InfoDetail infoDetail1 in infoDetails)
                                                {
                                                    infoDetail1.Date = date.Value.AddDays(infoDetail1.Count);
                                                }

                                                if (await _infoDetailServices.Update(infoDetails))
                                                {
                                                    data.success = true;
                                                }
                                            }
                                            else
                                            {
                                                data.success = true;
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    data.success = true;
                                }
                            }
                        }

                        if (data.success)
                        {
                            data.response = (await userController.Get(openId)).response;
                            data.msg      = "更新成功";
                            _userServices.GetAdo().CommitTran();
                        }
                        else
                        {
                            _userServices.GetAdo().RollbackTran();
                        }
                    }
                }
                return(data);
            }
            catch (Exception ex)
            {
                _userServices.GetAdo().RollbackTran();
                throw ex;
            }
        }
コード例 #3
0
        public async Task <MessageModel <List <AllData> > > Get(string openId = "123456", DateTime?date = null)
        {
            List <AllData> allDatas = new List <AllData>();

            if (!string.IsNullOrEmpty(openId))
            {
                User user = (await _userServices.Query(q => q.OpenId == openId)).FirstOrDefault();

                if (user != null)
                {
                    List <Info> infos = (await _infoServices.Query(q => q.OpenId == openId)).ToList();

                    foreach (Info info in infos)
                    {
                        List <InfoDetail> infoDetails = new List <InfoDetail>();

                        DateTime?lastMonth = null;

                        DateTime?nextMonth = null;

                        if (date != null)
                        {
                            lastMonth = new DateTime(date.Value.Year, date.Value.Month, 1).AddMonths(-1);

                            nextMonth = lastMonth.Value.AddMonths(3).AddDays(-1);
                        }

                        if (lastMonth != null && nextMonth != null)
                        {
                            infoDetails = (await _infoDetailServices.Query(q =>
                                                                           q.InfoId == info.InfoId &&
                                                                           SqlFunc.Between(q.Date.Value, lastMonth.Value, nextMonth.Value)
                                                                           )).ToList();
                        }
                        else
                        {
                            infoDetails = (await _infoDetailServices.Query(q =>
                                                                           q.InfoId == info.InfoId
                                                                           )).ToList();
                        }

                        allDatas.Add(new AllData()
                        {
                            user       = user,
                            info       = info,
                            infoDetail = infoDetails
                        });;
                    }
                }
                else
                {
                    allDatas = await UserInitialAsync(openId);
                }
            }

            return(new MessageModel <List <AllData> >()
            {
                msg = "获取成功",
                success = allDatas.Count > 0,
                response = allDatas
            });
        }