public async Task <IHttpActionResult> Post([FromBody] WishListApiModel wishList)
        {
            var incomingWishList = _mapper.Map <CoreModels.WishList>(wishList);
            var personService    = _personServiceFactory.Create(wishList.FamilyName);

            if (personService != null)
            {
                var person = await personService.GetByEmailOrTwitterAsync(incomingWishList.EmailAddress, incomingWishList.TwitterHandle);

                if (person == null)
                {
                    // TODO: Need to create a new person entry
                    person = new Core.Models.Person
                    {
                        BehaviorRating = (Core.Models.BehaviorRating)_random.Next((int)Core.Models.BehaviorRating.Unaware, (int)Core.Models.BehaviorRating.Angelic),
                        EmailAddress   = incomingWishList.EmailAddress,
                        FamilyName     = incomingWishList.FamilyName,
                        GivenName      = incomingWishList.GivenName,
                        TwitterHandle  = incomingWishList.TwitterHandle
                    };

                    if (!await personService.AddOrUpdateAsync(person))
                    {
                        return(Content(System.Net.HttpStatusCode.PreconditionFailed, new { message = "Unable to create person" }));
                    }
                }

                // Update wish list with person data
                incomingWishList.ActualBehaviorRating = person.BehaviorRating;
                incomingWishList.EmailAddress         = person.EmailAddress;
                incomingWishList.FamilyName           = person.FamilyName;
                incomingWishList.GivenName            = person.GivenName;
                incomingWishList.PersonId             = person.Id;
                incomingWishList.TwitterHandle        = person.TwitterHandle;
            }

            var reviewService = _reviewServiceFactory.Create();

            if (await reviewService.ReviewWishListAsync(incomingWishList))
            {
                var routeDictionary = new Dictionary <string, object>(ControllerContext.RouteData.Values)
                {
                    { "id", incomingWishList.PersonId }
                };

                return(CreatedAtRoute("DefaultApi", routeDictionary, new { message = "Wish List Accepted" }));
            }
            else
            {
                return(Content(System.Net.HttpStatusCode.ServiceUnavailable, new { message = "Wish List Processing Currently Unavailable" }));
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            XmlConfigurator.Configure(new FileInfo("logging.config"));

            log.Warn("test");
            log.Error("Just a test");
            Console.Write("Test");
            Console.ReadKey();

            var person = new Core.Models.Person("Allen", "Underwood", 21, "Male");

            Console.ReadKey();
        }