public void BuildingWithOrderSelectedRibbonId()
        {
            // add a temporary order
            Order order = new Order();
            string ribbonType = Rentler.Configuration.Ribbons.Current.AvailableRibbons.First().Key;
            OrderItem item = Rentler.Configuration.Products.GetProduct("ribbon").ToOrderItem(ribbonType, 1);
            order.OrderItems = new List<OrderItem>();
            order.OrderItems.Add(item);
            building.TemporaryOrder = order;

            // test
            PropertyPromoteInputModel model = new PropertyPromoteInputModel(building, featured);
            Assert.AreEqual(item.ProductOption, model.SelectedRibbonId);
        }
        public ActionResult Promote(PropertyPromoteInputModel input)
        {
            if (ModelState.IsValid)
            {
                // rebuild building
                Building building = input.ToBuilding();

                if (string.IsNullOrWhiteSpace(input.SelectedRibbonId) || input.SelectedRibbonId.ToLower() == "none")
                    input.SelectedRibbonId = null;

                var status = this.propertyAdapter.UpdatePropertyPromotions(
                    User.Identity.Name,
                    building,
                    input.SelectedRibbonId,
                    input.FeaturedDates,
                    input.ListingHasPriority ? "prioritylisting" : string.Empty
                );

                if (status.StatusCode == 200)
                {
                    // see if user selected a ribbon or requested to feature their property (coming soon)
                    if (status.Result.TemporaryOrder == null)
                    {
                        this.propertyAdapter.ActivateBuilding(building.BuildingId, User.Identity.Name);

                        return RedirectToAction("complete", new { id = input.BuildingId });
                    }
                    else
                        return Redirect("/dashboard/order/checkout/" + status.Result.TemporaryOrderId);
                }

                HandleErrors(status);
            }

            var buildingVal = this.propertyAdapter.GetProperty(input.BuildingId, User.Identity.Name);

            if (buildingVal.StatusCode != 200)
                return this.NotFoundException();

            // reset model properties not persisted
            input.PrimaryPhotoId = buildingVal.Result.PrimaryPhotoId;
            input.PrimaryPhotoExtension = buildingVal.Result.PrimaryPhotoExtension;

            input.CalendarDates = new CalendarDatesModel();
            // TODO: also need to restore blackout and featured dates too

            if (input.CalendarDates.ReservedDates.Any())
                input.CalendarDates.ReservedDates =
                    input.FeaturedDates.Select(d => d.ToString("G")).ToArray();
            else
                input.CalendarDates.ReservedDates = new string[] { };

            PropertyPromoteModel model = new PropertyPromoteModel()
            {
                Input = input,
                StepsAvailable = GetStepsAvailable(buildingVal.Result)
            };

            // return the model back with model state errors
            return View(model);
        }
 public void BuildingWithNoOrderNullSelectedRibbon()
 {
     PropertyPromoteInputModel model = new PropertyPromoteInputModel(building, featured);
     Assert.IsNull(model.SelectedRibbonId);
     Assert.IsNull(model.SelectedRibbonName);
 }
        public void ToBuildingBasicInformation()
        {
            PropertyPromoteInputModel model = new PropertyPromoteInputModel(building, featured);
            var b = model.ToBuilding();

            Assert.AreEqual(b.Title, this.building.Title);
            Assert.AreEqual(b.BuildingId, this.building.BuildingId);
            Assert.AreEqual(b.Description, this.building.Description);
        }