コード例 #1
0
        public ActionResult History_InsertComment(OrderHistory_Add model)
        {
            var order = Db.Select <Order>(m => m.Where(x => x.Id == model.OrderId).Limit(1)).FirstOrDefault();

            if (order == null)
            {
                return(JsonError("Order is not found"));
            }

            Order_History k = new Order_History();

            k.Content    = model.Message;
            k.isPrivate  = false;
            k.OnDate     = DateTime.Now;
            k.Order_Id   = model.OrderId;
            k.UserName   = CurrentUser.FullName;
            k.UserId     = CurrentUser.Id;
            k.IsCustomer = true;
            Db.Insert <Order_History>(k);

            // update order to let them know we have new message from customer
            Db.UpdateOnly <Order>(new Order()
            {
                FlagHistoryMessage = (int)Enum_FlagOrderMessage.NewMessageFromCustomer
            },
                                  ev => ev.Update(p => new
            {
                p.FlagHistoryMessage
            }).Where(m => m.Id == order.Id));

            return(JsonSuccess("", "Your message has been sent to Photobookmart. Please wait while we are processing your order. "));
        }
コード例 #2
0
        public void AddHistory(long orderId, string content, string name, int user_id, bool isPrivate = false)
        {
            Order_History h = new Order_History();

            h.Content   = content;
            h.OnDate    = DateTime.Now;
            h.Order_Id  = orderId;
            h.UserName  = name;
            h.UserId    = user_id;
            h.isPrivate = isPrivate;
            Db.Insert <Order_History>(h);
            Db.Close();
        }
コード例 #3
0
        /// <summary>
        /// Promote ads
        /// </summary>
        /// <param name="paymentMethod"></param>
        /// <returns></returns>
        public bool AddPromotionsToClassifiedAd(string paymentMethod)
        {
            var itemsToPromote = GetUserShoppingCart();
            var total          = 0.0;
            var order          = new Order_History();

            using (var dbContextTransaction = CurrentDbContext.Database.BeginTransaction())
            {
                try
                {
                    var user = CurrentDbContext.Users.Include("PromotedClassifiedAds").Include("OrderHistory").SingleOrDefault(x => x.Id == CurrentUser.Id);
                    foreach (var itp in itemsToPromote)
                    {
                        var classified = CurrentDbContext.ClassifiedDB.Include("AdPromotion").SingleOrDefault(x => x.Id == itp.ClassifiedAdId);
                        order.Description += string.Format("<b>{0}</b><br>", classified.Title);
                        if (itp.BumpAdPIDays.HasValue)
                        {
                            classified.AdPromotion.BumpAd.StartDate = DateTime.Now;
                            classified.AdPromotion.BumpAd.EndDate   = DateTime.Now.AddDays(itp.BumpAdPIDays.Value);
                            classified.AdPromotion.BumpAd.Duration  = itp.BumpAdPIInterval.Value;
                            classified.AdPromotion.BumpAd.Status    = true;
                            // order summary
                            order.Description += string.Format("Bump Ad : {0:C}<br>", itp.BumpAdPIPrice);
                            total             += itp.BumpAdPIPrice.Value;
                            // Add to hangfire Queue
                        }
                        if (itp.TopAdPIDays.HasValue)
                        {
                            classified.AdPromotion.TopAd.EndDate  = classified.AdPromotion.TopAd.StartDate = DateTime.Now;
                            classified.AdPromotion.TopAd.Duration = itp.TopAdPIDays.Value;
                            classified.AdPromotion.TopAd.EndDate.Value.AddDays(itp.TopAdPIDays.Value);
                            classified.AdPromotion.TopAd.Status = true;
                            // order summary
                            order.Description += string.Format("Top Ad: {0:C}<br>", itp.TopAdPIPrice);
                            total             += itp.TopAdPIPrice.Value;
                            // Add to hangfire Queue
                        }
                        if (itp.FeaturedAdPIDays.HasValue)
                        {
                            classified.AdPromotion.FeaturedAd.EndDate  = classified.AdPromotion.FeaturedAd.StartDate = DateTime.Now;
                            classified.AdPromotion.FeaturedAd.Duration = itp.FeaturedAdPIDays.Value;
                            classified.AdPromotion.FeaturedAd.EndDate.Value.AddDays(itp.FeaturedAdPIDays.Value);
                            classified.AdPromotion.FeaturedAd.Status = true;
                            // order summary
                            order.Description += string.Format("Featured Ad: {0:C}<br>", itp.FeaturedAdPIPrice);
                            total             += itp.FeaturedAdPIDays.Value;
                            // Add to hangfire Queue
                        }
                        if (itp.UrgentAdPIDays.HasValue)
                        {
                            classified.AdPromotion.UrgentAd.StartDate = DateTime.Now;
                            classified.AdPromotion.UrgentAd.Status    = true;
                            // order summary
                            order.Description += string.Format("Urgent Ad: {0:C}<br>", itp.UrgentAdPIPrice);
                            total             += itp.UrgentAdPIPrice.Value;
                        }
                        CurrentDbContext.SaveChanges();
                        // Remove old Lucene
                        LuceneSearch.ClearLuceneIndexRecord(itp.ClassifiedAdId);
                        // Add to Lucene
                        LuceneSearch.AddUpdateLuceneIndex(classified);
                    }
                    order.Description += string.Format("<b>Payment Method: {0:C} via {1}</b>", total, paymentMethod);
                    order.Date         = DateTime.Now;
                    // Ad order to user
                    CurrentDbContext.UserOrdersDB.Add(order);
                    user.OrderHistory.Add(order);
                    CurrentDbContext.SaveChanges();
                    dbContextTransaction.Commit();

                    foreach (var itp in itemsToPromote)
                    {
                        if (itp.BumpAdPIDays.HasValue)
                        {
                            // Add to hangfire Queue
                        }
                        if (itp.TopAdPIDays.HasValue)
                        {
                            // Add to hangfire Queue
                        }
                        if (itp.FeaturedAdPIDays.HasValue)
                        {
                            // Add to hangfire Queue
                        }
                        RemoveFromShoppingCart(itp.ClassifiedAdId);
                    }
                    return(true);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
        }