private Subscription InitializeAnonymousSubscription(ManBoxEntities ent) { var newSubscription = new Subscription() { Token = Guid.NewGuid().ToString(), CreatedDatetime = DateTime.Now, IsActive = true, IsPaused = false, SubscriptionStateCV = CodeValues.SubscriptionState.InCart }; var newSubscriptionDelivery = new SubscriptionDelivery() { DeliveryDate = DateTime.Now.AddDays(defaultNextDeliveryInDays), DeliveryStateCV = CodeValues.DeliveryState.New, QueuedDatetime = DateTime.Now, DeliveryPaymentStatusCV = CodeValues.DeliveryPaymentStatus.None }; newSubscription.SubscriptionDeliveries.Add(newSubscriptionDelivery); ent.Subscriptions.Add(newSubscription); ent.SaveChanges(); return(newSubscription); }
private Subscription InitializeGiftOrderForSubscribedCustomer(ManBoxEntities ent, string existingSubToken) { var existingSub = ent.Subscriptions.Single(s => s.Token == existingSubToken); var newGiftOrder = new Subscription() { Token = Guid.NewGuid().ToString(), CreatedDatetime = DateTime.Now, IsActive = true, IsPaused = false, SubscriptionStateCV = CodeValues.SubscriptionState.InCart, Gift = new Gift(), User = existingSub.User }; var newSubscriptionDelivery = new SubscriptionDelivery() { DeliveryDate = DateTime.Now.AddDays(defaultNextDeliveryInDays), DeliveryStateCV = CodeValues.DeliveryState.New, QueuedDatetime = DateTime.Now, DeliveryPaymentStatusCV = CodeValues.DeliveryPaymentStatus.None }; newGiftOrder.SubscriptionDeliveries.Add(newSubscriptionDelivery); ent.Subscriptions.Add(newGiftOrder); ent.SaveChanges(); return(newGiftOrder); }
/// <summary> /// controls which notification message must be displayed in the cart /// </summary> /// <param name="sub"></param> /// <param name="delivery"></param> /// <returns></returns> private string GetCartNotificationMessage(Subscription sub, SubscriptionDelivery delivery = null) { string message = string.Empty; if (sub == null) { return(UITexts.CartEmptyNotif); } if (sub.SubscriptionStateCV == CodeValues.SubscriptionState.Subscribed) { if (IdHelper.CurrentUser.IsAuthenticated && delivery != null) { if (delivery.DeliveryStateCV == CodeValues.DeliveryState.Processing) { return(UITexts.CartFrozenNotif); } else { return(string.Format("{0} {1}", UITexts.CartModificationNotif, delivery.DeliveryDate.Value.ToString("d MMMM yyyy"))); } } else { return(string.Format(UITexts.WelcomeBackLogIn, sub.User.FirstName)); } } else if (delivery == null || !delivery.SubscriptionDeliveryModels.Any()) { return(UITexts.CartEmptyNotif); } return(string.Empty); }
private List <ProductSelectionViewModel> GetSubscriptionDeliveryProducts(SubscriptionDelivery delivery, ManBoxEntities ent) { int langId = IdHelper.CurrentUser.LanguageId; List <ProductSelectionViewModel> selectedProducts = new List <ProductSelectionViewModel>(); delivery.SubscriptionDeliveryModels.Where(m => m.PackId == null).ToList().ForEach(m => selectedProducts.Add(new ProductSelectionViewModel() { ModelId = m.ModelId, ModelName = m.Model.Name, ProductId = m.Model.ProductId, ProductTitle = (from tt in ent.TranslationTexts where tt.LanguageId == langId && tt.TranslationId == m.Model.Product.TitleTrId select tt.Text).FirstOrDefault(), ProductReference = m.Model.Product.Reference, Quantity = m.Quantity, UnitPrice = m.Model.ShopPrice.ToCurrency(), SubTotalPrice = (m.Quantity * m.Model.ShopPrice).ToCurrency(), Models = (from mo in ent.Models where mo.ProductId == m.Model.ProductId select new ModelViewModel() { ModelId = mo.ModelId, Name = mo.Name, ShopPrice = mo.ShopPrice, ProductId = mo.ProductId }).ToList() })); // order model sizes selectedProducts.ForEach(p => p.Models = p.Models.OrderBy(m => m.Name).OrderBy(m => sizeOrder.IndexOf(m.Name))); return(selectedProducts); }
private void UpdateStock(SubscriptionDelivery delivery, ManBoxEntities ent) { foreach (var sm in delivery.SubscriptionDeliveryModels) { sm.Model.AmountInStock -= sm.Quantity; } ent.SaveChanges(); }
public static void StoreDeliveryMessage(SubscriptionDelivery delivery, string messageTypeCV) { if (!CodeValues.DeliveryMessageType.GetAll().Any(c => c == messageTypeCV)) { throw new Exception("Unexpected codevalue for deliverymessage"); } delivery.SubscriptionDeliveryMessages.Add(new SubscriptionDeliveryMessage() { DeliveryMessageTypeCV = messageTypeCV, SentDatetime = DateTime.Now }); }
private PackSelectionViewModel GetSubscriptionDeliveryPack(SubscriptionDelivery delivery, ManBoxEntities ent) { int langId = IdHelper.CurrentUser.LanguageId; List <ProductSelectionViewModel> selectedProducts = new List <ProductSelectionViewModel>(); // note: there can only be one pack var packItems = delivery.SubscriptionDeliveryModels.Where(m => m.PackId != null).OrderByDescending(m => m.ModelId); if (!packItems.Any()) { return(new PackSelectionViewModel()); } var pack = packItems.First().Pack; var packViewModel = new PackSelectionViewModel() { PackId = pack.PackId, Price = pack.ShopPrice.ToCurrency(), SelectedProducts = new List <ProductSelectionViewModel>(), Title = (from tt in ent.TranslationTexts where tt.LanguageId == langId && tt.TranslationId == pack.TitleTrId select tt.Text).FirstOrDefault() + " Pack" }; packItems.ToList().ForEach(i => packViewModel.SelectedProducts.Add( new ProductSelectionViewModel() { ModelId = i.ModelId, ModelName = i.Model.Name, ProductId = i.Model.ProductId, ProductReference = i.Model.Product.Reference, ProductTitle = (from tt in ent.TranslationTexts where tt.LanguageId == langId && tt.TranslationId == i.Model.Product.TitleTrId select tt.Text).FirstOrDefault(), Quantity = i.Quantity, SubTotalPrice = null, // price is at pack level UnitPrice = null, Models = (from m in ent.Models where m.ProductId == i.Model.ProductId select new ModelViewModel() { ModelId = m.ModelId, Name = m.Name, ShopPrice = m.ShopPrice, ProductId = m.ProductId, PackId = pack.PackId }).ToList() }) ); // order model sizes packViewModel.SelectedProducts.ForEach(p => p.Models = p.Models.OrderBy(m => m.Name).OrderBy(m => sizeOrder.IndexOf(m.Name))); return(packViewModel); }
private SubscriptionDelivery GetCopyNewDelivery(SubscriptionDelivery delivery) { var newDelivery = new SubscriptionDelivery() { DeliveryStateCV = CodeValues.DeliveryState.New, DeliveryDate = delivery.DeliveryDate, DeliveryPaymentStatusCV = CodeValues.DeliveryPaymentStatus.None, QueuedDatetime = delivery.QueuedDatetime, ShippingFee = 0 }; delivery.SubscriptionDeliveryModels.ToList().ForEach(m => newDelivery.SubscriptionDeliveryModels.Add(new SubscriptionDeliveryModel() { ModelId = m.ModelId, Quantity = m.Quantity }) ); return(newDelivery); }
private SubscriptionDelivery GetCopyPendingDelivery(SubscriptionDelivery delivery) { var newDelivery = new SubscriptionDelivery() { DeliveryStateCV = CodeValues.DeliveryState.Pending, DeliveryDate = delivery.DeliveryDate.Value.AddMonths(3), DeliveryPaymentStatusCV = CodeValues.DeliveryPaymentStatus.None, QueuedDatetime = DateTime.Now, ShippingFee = delivery.ShippingFee }; delivery.SubscriptionDeliveryModels.ToList().ForEach(m => newDelivery.SubscriptionDeliveryModels.Add(new SubscriptionDeliveryModel() { ModelId = m.ModelId, Quantity = m.Quantity, PackId = m.PackId }) ); return(newDelivery); }
private void SendShipmentConfirmationMail(SubscriptionDelivery delivery, ManBoxEntities ent) { try { var itemsTotal = delivery.Amount; var shippingFee = delivery.ShippingFee; var total = itemsTotal + shippingFee - delivery.CouponAmount; var sub = delivery.Subscription; List <MailProduct> mailProducts = new List <MailProduct>(); delivery.SubscriptionDeliveryModels.ToList().ForEach(m => mailProducts.Add( new Common.Mail.Models.MailProduct() { Price = m.Model.ShopPrice, Quantity = m.Quantity, ProductName = (from tt in ent.TranslationTexts where tt.TranslationId == m.Model.Product.TitleTrId && tt.LanguageId == sub.User.LanguageId select tt.Text).FirstOrDefault(), ModelName = m.Model.Name, TotalPrice = m.Quantity * m.Model.ShopPrice }) ); var domain = Utilities.GetCountryDomain(sub.User.Country.IsoCode); var toEmail = new MailRecipient(sub.User.Email, sub.User.FirstName); var fromEmail = new MailRecipient("support@" + domain, "ManBox"); mailService.SendMail <ShipmentConfirmationMail>( toEmail, fromEmail, new ShipmentConfirmationMail() { RootUrl = "http://" + domain, LanguageIso = sub.User.Language.IsoCode, Date = DateTime.Now, Name = sub.User.FirstName, Subject = UITexts.ResourceManager.GetString("MailShipmentConfirmationSubject", CultureInfo.CreateSpecificCulture(sub.User.Language.IsoCode)), Products = mailProducts, SubTotal = itemsTotal, Total = total, ShippingFee = shippingFee, CouponAmount = delivery.CouponAmount, CouponLabel = Utilities.GetCouponLabel(delivery.Coupon), Address = new MailAddress() { FirstName = sub.Address.FirstName, LastName = sub.Address.LastName, Street = sub.Address.Street, PostalCode = sub.Address.PostalCode, Province = sub.Address.Province, City = sub.Address.City } }); } catch (Exception e) { logger.Log(e); } }