示例#1
0
 private void MapForUpdateEntity(BL.CartLine entity, DA.CartLine daEntity)
 {
     daEntity.Id       = entity.Id;
     daEntity.Price    = entity.Price;
     daEntity.Quantity = entity.Quantity;
     daEntity.UserId   = entity.UserId;
     //daEntity.User = _mapper.Map<DA.User>(entity);
     daEntity.ProductId = entity.ProductId;
     //daEntity.Product = _mapper.Map<DA.Product>(entity);
 }
示例#2
0
        public async Task <int> SaveAsync(BL.CartLine entity)
        {
            try
            {
                if (entity == null)
                {
                    return(0);
                }

                using (var context = _contextFactory.GetProductContext())
                {
                    var entityModel = await context
                                      .CartLines
                                      .FirstOrDefaultAsync(item => item.Id.Equals(entity.Id));

                    if (entityModel == null)
                    {
                        entityModel = new DA.CartLine();
                        MapForUpdateEntity(entity, entityModel);

                        await context.CartLines.AddAsync(entityModel);
                    }
                    else
                    {
                        MapForUpdateEntity(entity, entityModel);
                    }

                    context.SaveChanges();
                    return(entityModel.Id);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }