Пример #1
0
        public async Task <long> ForwardAsync(long taskId, long userId, string imgUrl)
        {
            using (MyDbContext dbc = new MyDbContext())
            {
                ForwardEntity forward = await dbc.GetAll <ForwardEntity>().Include(f => f.Task).SingleOrDefaultAsync(t => t.UserId == userId && t.TaskId == taskId && t.State.Name == "已接受");

                if (forward == null)
                {
                    return(-1);
                }
                if (forward.Task.IsEnabled == false)
                {
                    return(-2);
                }

                //if(string.IsNullOrEmpty(await dbc.GetParameterAsync<UserEntity>(u => u.Id == userId, u => u.Mobile)))
                //{
                //    return -3;
                //}

                long stateId = await dbc.GetIdAsync <ForwardStateEntity>(f => f.Name == "审核中");

                if (stateId <= 0)
                {
                    return(-4);
                }
                forward.ImgUrl  = imgUrl;
                forward.StateId = stateId;
                await dbc.SaveChangesAsync();

                return(forward.Id);
            }
        }
Пример #2
0
        public async Task <long> GiveUpAsync(long taskId, long userId)
        {
            using (MyDbContext dbc = new MyDbContext())
            {
                if ((await dbc.GetIdAsync <TaskEntity>(t => t.Id == taskId)) <= 0)
                {
                    return(-1);
                }
                long stateId = await dbc.GetIdAsync <ForwardStateEntity>(f => f.Name == "已放弃");

                if (stateId <= 0)
                {
                    return(-2);
                }
                ForwardEntity forward = await dbc.GetAll <ForwardEntity>().Include(f => f.State).SingleOrDefaultAsync(f => f.UserId == userId && f.TaskId == taskId && f.State.Name == "已接受");

                if (forward == null)
                {
                    return(-3);
                }
                forward.StateId = stateId;
                await dbc.SaveChangesAsync();

                return(forward.Id);
            }
        }
Пример #3
0
        public async Task <long> ConfirmAsync(long id, bool auditState)
        {
            using (MyDbContext dbc = new MyDbContext())
            {
                ForwardEntity forward = await dbc.GetAll <ForwardEntity>().Include(f => f.Task).SingleOrDefaultAsync(f => f.Id == id);

                if (forward == null)
                {
                    return(-1);
                }
                if (forward.State.Name != "审核中")
                {
                    return(-6);//不是审核中的任务不能通过审核或取消审核
                }
                long stateId = await dbc.GetIdAsync <ForwardStateEntity>(f => f.Name == "未通过审核");

                if (stateId <= 0)
                {
                    return(-2);
                }
                if (auditState == false)
                {
                    forward.StateId = stateId;
                    await dbc.SaveChangesAsync();

                    return(forward.Id);
                }
                stateId = await dbc.GetIdAsync <ForwardStateEntity>(f => f.Name == "任务完成");

                forward.StateId = stateId;
                UserEntity user = await dbc.GetAll <UserEntity>().SingleOrDefaultAsync(u => u.Id == forward.UserId);

                if (user == null)
                {
                    return(-4);
                }
                decimal bonus = forward.Task.Bonus;
                user.Amount      = user.Amount + bonus;
                user.BonusAmount = user.BonusAmount + bonus;
                long journalTypeId = await dbc.GetIdAsync <IdNameEntity>(f => f.Name == "任务转发");

                if (journalTypeId <= 0)
                {
                    return(-5);
                }
                JournalEntity journal = new JournalEntity();
                journal.BalanceAmount = user.Amount;
                journal.ForwardId     = forward.Id;
                journal.TaskId        = forward.TaskId;
                journal.InAmount      = bonus;
                journal.JournalTypeId = journalTypeId;
                journal.Remark        = "任务转发获得佣金";
                journal.UserId        = user.Id;
                dbc.Journals.Add(journal);
                await dbc.SaveChangesAsync();

                return(forward.Id);
            }
        }
Пример #4
0
 static void Main(string[] args)
 {
     using (MyDbContext dbc = new MyDbContext())
     {
         dbc.Database.Log = (sql) =>
         {
             Console.WriteLine(sql);
         };
         ForwardEntity forward = dbc.GetAll <ForwardEntity>().SingleOrDefault(f => f.UserId == 1 && f.TaskId == 4 && f.State.Name == "已接受");
     }
     Console.ReadKey();
 }
Пример #5
0
        public async Task <long> AcceptAsync(long taskId, long userId)
        {
            using (MyDbContext dbc = new MyDbContext())
            {
                TaskEntity task = await dbc.GetAll <TaskEntity>().SingleOrDefaultAsync(t => t.Id == taskId);

                if (task == null)
                {
                    return(-1);
                }
                if (task.IsEnabled == false)
                {
                    return(-2);
                }

                //if (string.IsNullOrEmpty(await dbc.GetParameterAsync<UserEntity>(u => u.Id == userId, u => u.Mobile)))
                //{
                //    return -3;
                //}

                long stateId = await dbc.GetIdAsync <ForwardStateEntity>(f => f.Name == "已接受");

                if (stateId <= 0)
                {
                    return(-4);
                }

                ForwardEntity forward = await dbc.GetAll <ForwardEntity>().Include(f => f.State).SingleOrDefaultAsync(f => f.UserId == userId && f.TaskId == taskId);

                if (forward == null)
                {
                    forward         = new ForwardEntity();
                    forward.TaskId  = taskId;
                    forward.UserId  = userId;
                    forward.StateId = stateId;
                    dbc.Forwards.Add(forward);
                    await dbc.SaveChangesAsync();

                    return(forward.Id);
                }
                if (forward.State.Name != "未通过审核")
                {
                    return(-5);
                }
                forward.StateId = stateId;
                forward.ImgUrl  = "";
                await dbc.SaveChangesAsync();

                return(forward.Id);
            }
        }
Пример #6
0
        public async Task <bool> DelAsync(long id, long userId)
        {
            using (MyDbContext dbc = new MyDbContext())
            {
                ForwardEntity forward = await dbc.GetAll <ForwardEntity>().SingleOrDefaultAsync(f => f.TaskId == id && f.UserId == userId);

                if (forward == null)
                {
                    return(false);
                }
                dbc.Forwards.Remove(forward);
                await dbc.SaveChangesAsync();

                return(true);
            }
        }
Пример #7
0
        public ForwardDTO ToDTO(ForwardEntity entity)
        {
            ForwardDTO dto = new ForwardDTO();

            dto.CreateTime     = entity.CreateTime;
            dto.Id             = entity.Id;
            dto.ImgUrl         = entity.ImgUrl;
            dto.StateId        = entity.StateId;
            dto.StateName      = entity.State.Name;
            dto.TaskId         = entity.TaskId;
            dto.TaskTitle      = entity.Task.Title;
            dto.UserId         = entity.UserId;
            dto.UserName       = entity.User.Name;
            dto.Amount         = entity.User.Amount;
            dto.TakeCashAmount = entity.User.TakeCashAmount;
            dto.BonusAmount    = entity.User.BonusAmount;
            return(dto);
        }