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 Result <SocialMediaPlatform> GetSocialMediaPlatform(int platformId) { var socialMediaPlatform = _socialMediaPlatformRepository.GetSocialMediaPlatform(platformId); return((socialMediaPlatform != null) ? Result.Success <SocialMediaPlatform>(socialMediaPlatform) : Result.Failure <SocialMediaPlatform>(new ObjectNotFoundError($"No social media platform was found with the id {platformId}"))); }
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; } }
public SocialMediaPlatform GetSocialMediaPlatform(int platformId) { return(_socialMediaPlatformRepository.GetSocialMediaPlatform(platformId)); }