public Result <FoodTruck> CreateFoodTruck(CreateFoodTruckCommand foodTruckInfo) { // Creates our Food Truck object var foodTruck = new FoodTruck(foodTruckInfo.Name, foodTruckInfo.Description, foodTruckInfo.Website); // Converts tag strings into tag objects (including creating tags that don't exist) var tagObjects = DecodeTags(foodTruckInfo.Tags); // Attaches the tags to the Food Truck Object tagObjects.ForEach(obj => foodTruck.AddTag(obj)); // Social Media Accounts foreach (var accountInfo in foodTruckInfo.SocialMediaAccounts) { var platform = _socialMediaPlatformRepository.GetSocialMediaPlatform(accountInfo.SocialMediaPlatformId); if (platform == null) { throw new InvalidDataException($"The id {accountInfo.SocialMediaPlatformId} is not a valid social media platform id"); } SocialMediaAccount account = new SocialMediaAccount(platform, foodTruck, accountInfo.AccountName); foodTruck.AddSocialMediaAccount(account); } // Persist to the database _foodTruckRepository.Save(foodTruck); UnitOfWork.SaveChanges(); return(Result.Success <FoodTruck>(foodTruck)); }
public FoodTruck CreateFoodTruck(CreateFoodTruckCommand foodTruckInfo) { try { // Creates our Food Truck object var foodTruck = new FoodTruck(foodTruckInfo.Name, foodTruckInfo.Description, foodTruckInfo.Website); // Converts tag strings into tag objects (including creating tags that don't exist) var tagObjects = this.DecodeTags(foodTruckInfo.Tags); // Attaches the tags to the Food Truck Object tagObjects.ForEach(obj => foodTruck.AddTag(obj)); // Persist to the database this.foodTruckRepository.Save(foodTruck); this.UnitOfWork.SaveChanges(); return(foodTruck); } catch (Exception ex) { Logger.LogError(new EventId(104), ex, $"Error thrown while calling FoodTruckService.CreateFoodTruck()"); throw; } }
public FoodTruck CreateFoodTruck(CreateFoodTruckCommand foodTruckInfo) { try { // Creates our Food Truck object var foodTruck = new FoodTruck(foodTruckInfo.Name, foodTruckInfo.Description, foodTruckInfo.Website); // Converts tag strings into tag objects (including creating tags that don't exist) var tagObjects = DecodeTags(foodTruckInfo.Tags); // Attaches the tags to the Food Truck Object tagObjects.ForEach(obj => foodTruck.AddTag(obj)); // Social Media Accounts foreach (var accountInfo in foodTruckInfo.SocialMediaAccounts) { var platform = _socialMediaPlatformRepository.GetSocialMediaPlatform(accountInfo.SocialMediaPlatformId); if (platform == null) { throw new InvalidDataException($"The id {accountInfo.SocialMediaPlatformId} is not a valid social media platform id"); } SocialMediaAccount account = new SocialMediaAccount(platform, foodTruck, accountInfo.AccountName); foodTruck.AddSocialMediaAccount(account); } // Persist to the database _foodTruckRepository.Save(foodTruck); UnitOfWork.SaveChanges(); return(foodTruck); } catch (Exception ex) { Logger.LogError(new EventId(104), ex, $"Error thrown while calling FoodTruckService.CreateFoodTruck()"); throw; } }