Beispiel #1
0
 private static void ToRow(Restaurant obj, RestaurantRow row)
 {
     // TODO
     row.Id    = obj.Id.Value;
     row.Name  = obj.Name;
     row.Image = obj.Image;
     if (obj.Address != null)
     {
         row.AddressStreet  = obj.Address.Street;
         row.AddressZipCode = obj.Address.ZipCode;
         row.AddressCity    = obj.Address.City;
     }
     row.DeliveryTimes = new List <DeliveryTimeRow>();
     if (obj.DeliveryTimes != null && obj.DeliveryTimes.Count > 0)
     {
         foreach (var deliveryTime in obj.DeliveryTimes)
         {
             row.DeliveryTimes.Add(new DeliveryTimeRow
             {
                 RestaurantId = obj.Id.Value,
                 DayOfWeek    = deliveryTime.DayOfWeek,
                 StartTime    = (int)deliveryTime.Start.TotalMinutes,
                 EndTime      = (int)deliveryTime.End.TotalMinutes
             });
         }
     }
     row.MinimumOrderValue        = obj.MinimumOrderValue;
     row.DeliveryCosts            = obj.DeliveryCosts;
     row.Phone                    = obj.Phone;
     row.WebSite                  = obj.WebSite;
     row.Imprint                  = obj.Imprint;
     row.OrderEmailAddress        = obj.OrderEmailAddress;
     row.RestaurantPaymentMethods = new List <RestaurantPaymentMethodRow>();
     if (obj.PaymentMethods != null && obj.PaymentMethods.Count > 0)
     {
         foreach (var paymentMethod in obj.PaymentMethods)
         {
             row.RestaurantPaymentMethods.Add(new RestaurantPaymentMethodRow
             {
                 RestaurantId    = obj.Id.Value,
                 PaymentMethodId = paymentMethod.Value
             });
         }
     }
     row.RestaurantUsers = new List <RestaurantUserRow>();
     if (obj.Administrators != null && obj.Administrators.Count > 0)
     {
         foreach (var administrator in obj.Administrators)
         {
             row.RestaurantUsers.Add(new RestaurantUserRow
             {
                 RestaurantId = obj.Id.Value,
                 UserId       = administrator.Value
             });
         }
     }
 }
Beispiel #2
0
 private static Restaurant FromRow(RestaurantRow row)
 {
     return(new Restaurant(new RestaurantId(row.Id),
                           row.Name,
                           row.Image,
                           new Address(row.AddressStreet, row.AddressZipCode, row.AddressCity),
                           row.DeliveryTimes.Select(en => new DeliveryTime(en.DayOfWeek, TimeSpan.FromMinutes(en.StartTime), TimeSpan.FromMinutes(en.EndTime))).ToList(),
                           row.MinimumOrderValue,
                           row.DeliveryCosts,
                           row.Phone,
                           row.WebSite,
                           row.Imprint,
                           row.OrderEmailAddress,
                           new HashSet <PaymentMethodId>(row.RestaurantPaymentMethods.Select(en => new PaymentMethodId(en.PaymentMethodId))),
                           new HashSet <UserId>(row.RestaurantUsers.Select(en => new UserId(en.UserId)))
                           ));
 }
Beispiel #3
0
        public Task StoreAsync(Restaurant restaurant, CancellationToken cancellationToken = default)
        {
            return(Task.Factory.StartNew(() =>
            {
                var dbSet = dbContext.Restaurants;

                var row = dbSet.FirstOrDefault(x => x.Id == restaurant.Id.Value);
                if (row != null)
                {
                    ToRow(restaurant, row);
                    dbSet.Update(row);
                }
                else
                {
                    row = new RestaurantRow();
                    ToRow(restaurant, row);
                    dbSet.Add(row);
                }

                dbContext.SaveChanges();
            }, cancellationToken));
        }