Example #1
0
        public async Task <int> SaveAsync(BL.Order entity)
        {
            try
            {
                if (entity == null)
                {
                    return(0);
                }

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

                    if (entityModel == null)
                    {
                        entityModel = new DA.Order();
                        MapForUpdateEntity(entity, entityModel);
                        await context.Orders.AddAsync(entityModel);
                    }
                    else
                    {
                        MapForUpdateEntity(entity, entityModel);
                    }

                    context.SaveChanges();
                    return(entityModel.Id);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #2
0
 private void MapForUpdateEntity(BL.Order entity, DA.Order daEntity)
 {
     daEntity.Id        = entity.Id;
     daEntity.Name      = entity.Name;
     daEntity.Surname   = entity.Surname;
     daEntity.Address   = entity.Address;
     daEntity.Phone     = entity.Phone;
     daEntity.Email     = entity.Email;
     daEntity.OrderTime = entity.OrderTime;
     daEntity.Amount    = entity.Amount;
 }