コード例 #1
0
        //[Route("Update")]
        public async Task <MessageModel <List <AllData> > > Put(string openId, int infoId, string infoDetailId, 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 infoDetail = (await _infoDetailServices.QueryById(infoDetailId));

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

                        if (infoDetail != null && infoDetailInitail != null)
                        {
                            infoDetail.Count = addCount;
                            infoDetail.Type  = type;
                            infoDetail.Date  = GetDate(infoDetailInitail.Date.Value, addCount, type);

                            if (await _userServices.Update(user) && await _infoDetailServices.Update(infoDetail))
                            {
                                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;
            }
        }