public object Any(Services.SetSocialMediaAccount request)
        {
            SocialMediaPlatform platform = null;

            try
            {
                platform = SocialMediaPlatform.FromDisplayName <SocialMediaPlatform>(request.Platform);
            }

            catch
            {
                return(string.Format("Please use one of those platforms {0}", string.Join(',', SocialMediaPlatform.GetAll <SocialMediaPlatform>().Select(w => w.Name))));
            }


            var socialMediaAccount = dbContext.SocialMediaAccounts.Where(sm => sm.PlatformId == platform.Id).SingleOrDefault();

            if (socialMediaAccount == null)
            {
                socialMediaAccount = new SocialMediaAccount()
                {
                    PlatformId = platform.Id, Username = request.Username
                };
                socialMediaAccount.Version = 1;
                dbContext.SocialMediaAccounts.Add(socialMediaAccount);
                dbContext.SaveChanges();
                return(true);
            }


            socialMediaAccount.Username = request.Username;
            dbContext.SaveChanges();
            return(true);
        }
Exemple #2
0
        public FoodTrucksControllerTests()
        {
            Tag tagOne   = new Tag(1, "Tag One");
            Tag tagTwo   = new Tag(2, "Tag Two");
            Tag tagThree = new Tag(3, "Tag Three");
            Tag tagFour  = new Tag(4, "Tag Four");

            SocialMediaPlatform facebook  = new SocialMediaPlatform(1, "Facebook", "http://facebook.com/{0}", null);
            SocialMediaPlatform twitter   = new SocialMediaPlatform(2, "Twitter", "http://twitter.com/{0}", null);
            SocialMediaPlatform instagram = new SocialMediaPlatform(3, "Instagram", "http://instagram.com/{0}", null);

            foodTruckOne = new FoodTruck(1, "Food Truck One", "Food Truck One Description", @"http://www.foodtruckone.com");
            foodTruckOne.AddTag(tagOne);
            foodTruckOne.AddTag(tagTwo);
            foodTruckOne.AddSocialMediaAccount(new SocialMediaAccount(facebook, foodTruckOne, "foodTruckOne"));
            foodTruckOne.AddSocialMediaAccount(new SocialMediaAccount(twitter, foodTruckOne, "foodTruckOne"));

            foodTruckTwo = new FoodTruck(2, "Food Truck Two", "Food Truck Two Description", @"http://www.foodtrucktwo.com");
            foodTruckTwo.AddTag(tagThree);
            foodTruckOne.AddSocialMediaAccount(new SocialMediaAccount(facebook, foodTruckTwo, "foodTruckTwo"));

            foodTruckThree = new FoodTruck(3, "Food Truck Two", "Food Truck Three Description", @"http://www.foodtruckthree.com");
            foodTruckThree.AddTag(tagOne);
            foodTruckThree.AddTag(tagFour);
            foodTruckThree.AddSocialMediaAccount(new SocialMediaAccount(facebook, foodTruckThree, "foodTruckThree"));
            foodTruckThree.AddSocialMediaAccount(new SocialMediaAccount(twitter, foodTruckThree, "foodTruckThree"));
            foodTruckThree.AddSocialMediaAccount(new SocialMediaAccount(instagram, foodTruckThree, "foodTruckThree"));

            foodTruckList = new List <FoodTruck>()
            {
                foodTruckOne, foodTruckTwo, foodTruckThree
            };


            var config = new MapperConfiguration(cfg => {
                cfg.AddProfile <FoodTruckModelAutomapperProfile>();
            });

            mapper = new Mapper(config,
                                t => FoodTrucksControllerTests.Resolve <Type, object>(t));
        }