public bool Create(DonationViewModel donation, List <string> categoriesId) { var model = new Donation(); model.Institution = _institutionService.Get(donation.InstitutionId.ToString()); model.PickUpTime = donation.PickUpDateOn.AddHours(donation.PickUpTimeOn.Hour).AddMinutes(donation.PickUpTimeOn.Hour); model.DonationId = Guid.NewGuid().ToString(); model.City = donation.City; model.DonationQuantity = donation.DonationQuantity; model.PhoneNumber = donation.PhoneNumber; model.Street = donation.Street; model.ZipCode = donation.ZipCode; model.PickUpComment = donation.PickUpComment; model.User = donation.User; _context.Donations.Add(model); _context.SaveChanges(); var donationsCategory = new List <DonationCategory>(); foreach (var item in categoriesId) { donationsCategory.Add(new DonationCategory() { CategoryId = item, DonationId = model.DonationId, Id = Guid.NewGuid().ToString() }); } _context.AddRange(donationsCategory); return(_context.SaveChanges() > 0); }