Ejemplo n.º 1
0
        private GoodsImgDTO ToDTO(GoodsImgEntity entity)
        {
            GoodsImgDTO dto = new GoodsImgDTO();

            dto.CreateTime  = entity.CreateTime;
            dto.Description = entity.Description;
            dto.Id          = entity.Id;
            dto.Name        = entity.Name;
            dto.ImgUrl      = entity.ImgUrl;
            return(dto);
        }
Ejemplo n.º 2
0
        public async Task <long> AddAsync(long goodsId, string name, string imgUrl, string description)
        {
            using (MyDbContext dbc = new MyDbContext())
            {
                GoodsImgEntity entity = new GoodsImgEntity();
                entity.Name        = name;
                entity.GoodsId     = goodsId;
                entity.ImgUrl      = imgUrl;
                entity.Description = description;
                dbc.GoodsImgs.Add(entity);
                await dbc.SaveChangesAsync();

                return(entity.Id);
            }
        }
Ejemplo n.º 3
0
        public async Task <long> AddAsync(long buyerId, long addressId, long payTypeId, long orderStateId, long goodsId, long number)
        {
            using (MyDbContext dbc = new MyDbContext())
            {
                OrderEntity entity = new OrderEntity();
                entity.Code         = CommonHelper.GetRandom3();
                entity.BuyerId      = buyerId;
                entity.AddressId    = addressId;
                entity.PayTypeId    = payTypeId;
                entity.OrderStateId = orderStateId;
                dbc.Orders.Add(entity);
                await dbc.SaveChangesAsync();

                GoodsEntity goods = await dbc.GetAll <GoodsEntity>().SingleOrDefaultAsync(g => g.Id == goodsId);

                if (goods == null)
                {
                    return(-1);
                }
                OrderListEntity listEntity = new OrderListEntity();
                listEntity.OrderId = entity.Id;
                listEntity.GoodsId = goodsId;
                listEntity.Number  = number;
                listEntity.Price   = goods.RealityPrice;
                GoodsImgEntity imgEntity = await dbc.GetAll <GoodsImgEntity>().FirstOrDefaultAsync(g => g.GoodsId == goodsId);

                if (imgEntity == null)
                {
                    listEntity.ImgUrl = "";
                }
                else
                {
                    listEntity.ImgUrl = imgEntity.ImgUrl;
                }
                listEntity.TotalFee = listEntity.Price * number;
                entity.Amount       = listEntity.TotalFee;
                dbc.OrderLists.Add(listEntity);
                await dbc.SaveChangesAsync();

                return(entity.Id);
            }
        }
Ejemplo n.º 4
0
        public async Task <long> AddAsync(long goodsId, List <string> imgUrls)
        {
            using (MyDbContext dbc = new MyDbContext())
            {
                await dbc.GetAll <GoodsImgEntity>().Where(g => g.GoodsId == goodsId).ForEachAsync(g => g.IsDeleted = true);

                foreach (string imgUrl in imgUrls)
                {
                    GoodsImgEntity entity = new GoodsImgEntity();
                    entity.Name        = "";
                    entity.GoodsId     = goodsId;
                    entity.ImgUrl      = imgUrl;
                    entity.Description = "";
                    dbc.GoodsImgs.Add(entity);
                }
                await dbc.SaveChangesAsync();

                return(1);
            }
        }