Ejemplo n.º 1
0
        public override void ExecuteOnComplete(Order order)
        {
            var tzi = TimeZoneInfo.FindSystemTimeZoneById("Mountain Standard Time");
            var today = DateTime.UtcNow.AddHours(tzi.GetUtcOffset(DateTime.Now).Hours);

            var featuredDate = DateTime.Parse(
                this.Item.ProductOption, null,
                System.Globalization.DateTimeStyles.AssumeUniversal);

            //make sure the featured day is scheduled to exactly midnight.
            featuredDate = featuredDate.Date.AddHours(-tzi.GetUtcOffset(featuredDate.Date).Hours);

            using(var context = new RentlerContext())
            {
                var building = context.Buildings.FirstOrDefault(b => b.BuildingId == order.BuildingId);

                if(building == null)
                    throw new ArgumentNullException("Building");

                context.FeaturedListings.Add(new FeaturedListing
                {
                    BuildingId = building.BuildingId,
                    ScheduledDate = featuredDate,
                    Zip = building.Zip
                });

                context.SaveChanges();
            }
        }
        public override void ExecuteOnComplete(Order order)
        {
            using (var context = new RentlerContext())
            {
                // get local date, to timestamp when the building was prioritized (so we can turn it off after 30 days)
                TimeZoneInfo mstTZ = TimeZoneInfo.FindSystemTimeZoneById("Mountain Standard Time");
                DateTime dateLocal = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, mstTZ);

                var building = context.Buildings.FirstOrDefault(b => b.BuildingId == order.BuildingId);

                if (building == null)
                    throw new ArgumentNullException("Building");

                building.HasPriority = true;
                building.DatePrioritized = dateLocal;

                context.SaveChanges();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Updates the promotional specific fields on Building
        /// </summary>
        /// <param name="username">owner of the building</param>
        /// <param name="building">the building</param>
        /// <returns>
        /// Status with the updated building
        /// </returns>
        public Status<Building> UpdatePropertyPromotions(string username, Building building,
			string ribbonId, IEnumerable<DateTime> featuredDates, string priorityListing)
        {
            if (building == null)
                return Status.ValidationError<Building>(null, "building", "building is null");

            using (RentlerContext context = new RentlerContext())
            {
                try
                {
                    Building current = (from b in context.Buildings
                                            .Include("User")
                                            .Include("TemporaryOrder")
                                        where b.IsDeleted == false &&
                                        b.BuildingId == building.BuildingId &&
                                        b.User.Username == username
                                        select b).SingleOrDefault();

                    if (current == null)
                        return Status.NotFound<Building>();

                    current.Title = building.Title;
                    current.Description = building.Description;

                    // validate the building
                    var validation = Status.Validatate<Building>(current);
                    if (validation.StatusCode != 200)
                        return validation;

                    // delete any old order
                    if (current.TemporaryOrder != null)
                        context.Orders.Remove(current.TemporaryOrder);

                    // add order with ribbon if items
                    if (!string.IsNullOrWhiteSpace(ribbonId) || featuredDates != null || !string.IsNullOrWhiteSpace(priorityListing))
                    {
                        Order order = new Order();
                        order.UserId = current.UserId;
                        order.BuildingId = current.BuildingId;
                        order.CreateDate = DateTime.UtcNow;
                        order.CreatedBy = "propertyAdapter";
                        order.OrderStatus = OrderStatus.New;

                        //calculate order total here
                        if (!string.IsNullOrWhiteSpace(ribbonId))
                            order.OrderTotal += Configuration.Products.GetProduct("ribbon")
                                .ToOrderItem(ribbonId, 1).Price;

                        if (featuredDates != null)
                            order.OrderTotal += Configuration.Products
                                .GetProduct("featureddate").ToOrderItem(
                                    DateTime.UtcNow.ToString("G"), 1).Price * featuredDates.Count();

                        if (!string.IsNullOrWhiteSpace(priorityListing))
                            order.OrderTotal += Configuration.Products
                                .GetProduct("prioritylisting").ToOrderItem(
                                    DateTime.UtcNow.ToString("G"), 1).Price;

                        context.Orders.Add(order);
                        context.SaveChanges();

                        current.TemporaryOrder = order;
                        current.TemporaryOrderId = order.OrderId;

                        // add ribbon
                        if (!string.IsNullOrWhiteSpace(ribbonId))
                        {
                            var ribbonItem = Configuration.Products.GetProduct("ribbon").ToOrderItem(ribbonId, 1);
                            ribbonItem.OrderId = order.OrderId;
                            context.OrderItems.Add(ribbonItem);
                        }

                        // add featured dates
                        if (featuredDates != null)
                        {
                            for (int i = 0; i < featuredDates.Count(); ++i)
                            {
                                // featured dates come through with no time, we we have to add it
                                DateTime date = featuredDates.ElementAt(i);
                                date = date.Add(DateTime.Now.TimeOfDay);

                                DateTime dateUtc = date.ToUniversalTime();
                                var featuredItem = Configuration.Products.GetProduct("featureddate").ToOrderItem(dateUtc.ToString("G"), 1);
                                featuredItem.OrderId = order.OrderId;
                                context.OrderItems.Add(featuredItem);
                            }
                        }

                        // add priority listing
                        if (!string.IsNullOrWhiteSpace(priorityListing))
                        {
                            var priorityItem =
                                Configuration.Products.GetProduct("prioritylisting")
                                .ToOrderItem(true.ToString(), 1);
                            priorityItem.OrderId = order.OrderId;
                            context.OrderItems.Add(priorityItem);
                        }
                    }

                    context.SaveChanges();

                    InvalidateCache(building.BuildingId);

                    return Status.OK<Building>(current);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    // log exception
                    return Status.Error<Building>(
                        "An unexpected error occurred while trying to save promotions. Contact Rentler support for assistance.",
                        building
                    );
                }
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Orders EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToOrders(Order order)
 {
     base.AddObject("Orders", order);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Create a new Order object.
 /// </summary>
 /// <param name="orderId">Initial value of the OrderId property.</param>
 /// <param name="userId">Initial value of the UserId property.</param>
 /// <param name="orderTotal">Initial value of the OrderTotal property.</param>
 /// <param name="createDate">Initial value of the CreateDate property.</param>
 /// <param name="orderStatusCode">Initial value of the OrderStatusCode property.</param>
 /// <param name="createdBy">Initial value of the CreatedBy property.</param>
 public static Order CreateOrder(global::System.Int32 orderId, global::System.Int32 userId, global::System.Decimal orderTotal, global::System.DateTime createDate, global::System.Int32 orderStatusCode, global::System.String createdBy)
 {
     Order order = new Order();
     order.OrderId = orderId;
     order.UserId = userId;
     order.OrderTotal = orderTotal;
     order.CreateDate = createDate;
     order.OrderStatusCode = orderStatusCode;
     order.CreatedBy = createdBy;
     return order;
 }