public bool UpdateRestaurant(Domain.Models.Restaurant restaurant) { var restauranto = _context.Restaurants.Single(r => r.Id == restaurant.Id); if (restaurant.ImageUrl != null) { restauranto.ImageUrl = restaurant.ImageUrl; } restauranto.MaxGuests = restaurant.MaxGuests; restauranto.PostalCode = restaurant.PostalCode; if (restauranto.Reservations != null) { restauranto.Reservations = restauranto.Reservations.ToList(); } restauranto.StreetAddress = restaurant.StreetAddress; restauranto.City = restaurant.City; restauranto.Description = restaurant.Description; restauranto.Active = restaurant.Active; restauranto.MaxPersonsBooking = restaurant.MaxPersonsBooking; restauranto.DayCapacity = restaurant.DayCapacity; restauranto.Name = restaurant.Name; for (int i = 0; i < 7; i++) { restauranto.OpenTimes[i].OpeningTime = restaurant.OpenTimes[i].OpeningTime; restauranto.OpenTimes[i].ClosingTime = restaurant.OpenTimes[i].ClosingTime; } if (restauranto.ClosedDates == null) { restauranto.ClosedDates = new List <CloseDate>(); } if (restauranto.ClosedDates.Count > 0) { for (int i = restauranto.ClosedDates.Count - 1; i >= 0; i--) { if (!restaurant.ClosedDates.Any(c => c.ClosedDate == restauranto.ClosedDates[i].ClosedDate)) { restauranto.ClosedDates.Remove(restauranto.ClosedDates[i]); } } foreach (var closedDate in restaurant.ClosedDates) { if (!restauranto.ClosedDates.Any(c => c.ClosedDate == closedDate.ClosedDate)) { restauranto.ClosedDates.Add(closedDate); } } } _context.SaveChanges(); if (restaurant.Id != 0) { return(true); } else { return(false); } }
public bool SaveRestaurant(Domain.Models.Restaurant restaurant) { var restaurants = _context.Restaurants; restaurants.Add(restaurant); _context.SaveChanges(); if (restaurant.Id != 0) { return(true); } else { return(false); } }