Esempio n. 1
0
        public async Task <bool> UpdateAsync(long id, string name, string codeUrl, string description)
        {
            using (MyDbContext dbc = new MyDbContext())
            {
                PayCodeEntity entity = await dbc.GetAll <PayCodeEntity>().SingleOrDefaultAsync(b => b.Id == id);

                if (entity == null)
                {
                    return(false);
                }
                if (!string.IsNullOrEmpty(name))
                {
                    entity.Name = name;
                }
                if (!string.IsNullOrEmpty(codeUrl))
                {
                    entity.CodeUrl = codeUrl;
                }
                if (!string.IsNullOrEmpty(description))
                {
                    entity.Description = description;
                }
                await dbc.SaveChangesAsync();

                return(true);
            }
        }
Esempio n. 2
0
        public PayCodeDTO ToDTO(PayCodeEntity entity)
        {
            PayCodeDTO dto = new PayCodeDTO();

            dto.Description = entity.Description;
            dto.Name        = entity.Name;
            dto.CreateTime  = entity.CreateTime;
            dto.Id          = entity.Id;
            dto.CodeUrl     = entity.CodeUrl;
            dto.UserId      = entity.UserId;
            return(dto);
        }
Esempio n. 3
0
        public async Task <long> AddAsync(long userId, string name, string codeUrl, string description)
        {
            using (MyDbContext dbc = new MyDbContext())
            {
                PayCodeEntity entity = new PayCodeEntity();
                entity.UserId      = userId;
                entity.Name        = name;
                entity.CodeUrl     = codeUrl;
                entity.Description = description;
                dbc.PayCodes.Add(entity);
                await dbc.SaveChangesAsync();

                return(entity.Id);
            }
        }
Esempio n. 4
0
        public async Task <bool> DeleteAsync(long id)
        {
            using (MyDbContext dbc = new MyDbContext())
            {
                PayCodeEntity entity = await dbc.GetAll <PayCodeEntity>().SingleOrDefaultAsync(g => g.Id == id);

                if (entity == null)
                {
                    return(false);
                }
                entity.IsDeleted = true;
                await dbc.SaveChangesAsync();

                return(true);
            }
        }