public ImageThumbnail GetImageThumbnailById(Guid id) { using (var context = new InstantStoreDataContext()) { return(context.ImageThumbnails.FirstOrDefault(x => x.Id == id)); } }
public void ChangePagePosition(Guid id, bool movedown) { using (var context = new InstantStoreDataContext()) { var page = context.ContentPages.FirstOrDefault(x => x.Id == id); if (page == null) { throw new ModelValidationException("UpdateContentPage.OriginalPageDoesNotExists"); } if (page.Position == 0 && !movedown) { return; } var siblingPages = context.ContentPages.Where(x => page.ParentId != null ? x.ParentId == page.ParentId : x.ParentId == null && x.Id != page.Id).ToList(); if (page.Position >= siblingPages.Count && movedown) { return; } int newPosition = page.Position + (movedown ? 1 : -1); var exchangePage = siblingPages.FirstOrDefault(x => x.Position == newPosition); if (exchangePage != null) { exchangePage.Position = page.Position; } page.Position = newPosition; context.SubmitChanges(); } }
public ActionResult NewUser(UserAuthViewModel userViewModel) { // TODO: DDoS vulnerability. Throttling by ip needs to be added here. if (userViewModel == null) { return(this.NewUser()); } using (var context = new InstantStoreDataContext()) { if (context.Users.ToList().Any(user => string.Equals(user.Email, userViewModel.Email, StringComparison.OrdinalIgnoreCase))) { this.ModelState.AddModelError(string.Empty, StringResource.UserAlreadyExists); } } this.Initialize(Guid.Empty, PageIdentity.Unknown); if (!this.ModelState.IsValid) { userViewModel.Password = ""; userViewModel.ConfirmPassword = ""; return(this.View("NewUserStep1", userViewModel)); } userViewModel.UserId = Guid.NewGuid(); this.Session[newUserSessionId] = userViewModel; return(this.View("NewUserStep2", new UserViewModel { NewUserId = userViewModel.UserId })); }
public IList <ContentPageAttachment> GetPageAttachments(Guid pageId) { using (var context = new InstantStoreDataContext()) { return(context.ContentPageAttachments.Where(x => x.PageId == pageId).OrderBy(x => x.Order).ToList()); } }
private OfferViewModel GetOffer(Order order, Currency currency) { using (var context = new InstantStoreDataContext()) { var availableOffer = context.Offers .Where( offer => offer.IsActive && offer.CurrencyId == currency.Id && offer.ThresholdPriceValue <= order.TotalPrice) .OrderByDescending( offer => offer.ThresholdPriceValue) .FirstOrDefault(); if (availableOffer != null) { return(new OfferViewModel { Id = availableOffer.VersionId, Name = availableOffer.Name, Type = (OfferDiscountType)availableOffer.DiscountType, Discount = availableOffer.DiscountValue, CurrencyText = availableOffer.Currency.Text }); } } return(null); }
public static object CreateCategoryViewModel( User user, ContentPage categoryPage, int count, int offset, ListingViewProductSettings displayHint) { if (categoryPage == null || !categoryPage.IsCategory()) { return(null); } using (var context = new InstantStoreDataContext()) { var category = context.Categories.FirstOrDefault(x => x.VersionId == categoryPage.CategoryId.Value); if (category == null) { throw new ArgumentException("Category does not exist for id."); } var productActionData = user != null && user.IsAdmin && displayHint == ListingViewProductSettings.AdminSettings ? new ProductActionData("Admin", "Product", categoryPage.Id) : new ProductActionData("Main", "Page", categoryPage.Id); var factory = category.ListType == 1 ? (IProductViewModelFactory) new ListProductViewModelFactory(context, user, categoryPage.Id, productActionData, count, offset) : (IProductViewModelFactory) new TileProductViewModelFactory(context, user, categoryPage.Id, productActionData, count, offset); return(factory.CreateProductViewModel()); } }
private void AddOrUpdateOrderItem(User user, Guid productId, int count, InstantStoreDataContext context, Order order) { var product = context.Products.FirstOrDefault(x => x.VersionId == productId); if (product == null) { throw new ModelValidationException("There are no product for the id."); } var existingOrder = context.OrderProducts.FirstOrDefault(x => x.ProductId == productId && x.OrderId == order.Id); if (existingOrder == null) { context.OrderProducts.InsertOnSubmit(new OrderProduct { Id = Guid.NewGuid(), Count = count, OrderId = order.Id, ProductId = productId, Price = product.GetPriceForUser(user, context.ExchangeRates), PriceCurrencyId = user.DefaultCurrencyId.Value }); } else { existingOrder.Count += count; existingOrder.Price = product.GetPriceForUser(user, context.ExchangeRates); existingOrder.PriceCurrencyId = user.DefaultCurrencyId.Value; } }
public Order AddItemToCurrentOrder(User user, Guid productId, int count) { using (var context = new InstantStoreDataContext()) { var order = context.Orders.FirstOrDefault(x => x.UserId == user.Id && x.Status == (int)OrderStatus.Active); if (order == null) { order = this.CreateOrderForUser(context, user.Id); } if (user.DefaultCurrencyId == null || user.DefaultCurrencyId == Guid.Empty) { throw new ModelValidationException("User has no currency assigned."); } if (order.Status != (int)OrderStatus.Active) { throw new ModelValidationException("Order has already been submitted."); } AddOrUpdateOrderItem(user, productId, count, context, order); context.SubmitChanges(); return(order); } }
public IList <OrderUpdate> GetStatusesForOrder(Guid orderId) { using (var context = new InstantStoreDataContext()) { return(context.OrderUpdates.Where(x => x.OrderId == orderId).ToList()); } }
public ContentPage GetPageByCategoryId(Guid id) { using (var context = new InstantStoreDataContext()) { return(context.ContentPages.FirstOrDefault(x => x.CategoryId != null && x.CategoryId == id)); } }
public IList <ContentPage> GetAllPages() { using (var context = new InstantStoreDataContext()) { return(context.ContentPages.ToList()); } }
public User GetUser(Guid id) { using (var context = new InstantStoreDataContext()) { return(context.Users.FirstOrDefault(user => user.Id == id)); } }
public IList <User> GetUsers(Func <User, bool> condition) { using (var context = new InstantStoreDataContext()) { return(context.Users.Where(condition).ToList()); } }
public IList <Category> GetPriorityCategories() { using (var context = new InstantStoreDataContext()) { return(context.Categories.Where(x => x.IsImportant).ToList()); } }
public void TrashPage(Guid id) { using (var context = new InstantStoreDataContext()) { var trashPage = context.ContentPages.FirstOrDefault(x => x.Id == TrashParentId); if (trashPage == null) { context.ContentPages.InsertOnSubmit(new ContentPage() { Id = TrashParentId, Name = "TRASH", Position = -1 }); } var page = context.ContentPages.FirstOrDefault(x => x.Id == id); if (page == null) { throw new ModelValidationException("UpdateContentPage.OriginalPageDoesNotExists"); } page.ParentId = TrashParentId; context.SubmitChanges(); } }
public Order GetOrderById(Guid orderId) { using (var context = new InstantStoreDataContext()) { return(context.Orders.FirstOrDefault(x => x.Id == orderId)); } }
public Category GetCategoryById(Guid id) { using (var context = new InstantStoreDataContext()) { return(context.Categories.FirstOrDefault(x => x.VersionId == id)); } }
public IList <ContentPage> GetPages(Guid?parentId, Func <ContentPage, bool> filter) { using (var context = new InstantStoreDataContext()) { var result = context.ContentPages.Where(x => (parentId != null ? x.ParentId == parentId : x.ParentId == null)); return(filter != null?result.Where(filter).ToList() : result.ToList()); } }
public ContentPage GetPageByProductId(Guid id) { using (var context = new InstantStoreDataContext()) { var categoryId = context.ProductToCategories.Where(x => x.ProductId == id).Select(x => x.CategoryId).First(); return(context.ContentPages.FirstOrDefault(x => x.CategoryId != null && x.CategoryId == categoryId)); } }
public int GetProductPosition(Guid id) { using (var context = new InstantStoreDataContext()) { var productCategory = context.ProductToCategories.Where(x => x.Product.VersionId == id).FirstOrDefault(); return(productCategory == null ? -1 : productCategory.Index); } }
public Order GetActiveOrder(Guid userId) { using (var context = new InstantStoreDataContext()) { var order = context.Orders.FirstOrDefault(x => x.UserId == userId && x.Status == (int)OrderStatus.Active); return(order == null?this.CreateOrderForUser(context, userId) : order); } }
public IList <Product> GetProductsByPopularity(int count) { using (var context = new InstantStoreDataContext()) { // TODO: query top products in orders. return(context.Products.Where(x => x.MainImageId != null).Take(count).ToList()); } }
public void DeleteTemplate(Guid id) { using (var context = new InstantStoreDataContext()) { var template = context.PropertyTemplates.FirstOrDefault(x => x.Id == id); context.PropertyTemplates.DeleteOnSubmit(template); context.SubmitChanges(); } }
public void BlockUser(Guid userId) { using (var context = new InstantStoreDataContext()) { var user = context.Users.First(u => u.Id == userId); user.IsBlocked = true; context.SubmitChanges(); } }
public void ActivateUser(Guid userId) { using (var context = new InstantStoreDataContext()) { var user = context.Users.FirstOrDefault(u => u.Id == userId); user.IsActivated = true; context.SubmitChanges(); } }
public string GetSettings(SettingsKey key) { using (var context = new InstantStoreDataContext()) { var keyString = key.ToString(); var setting = context.Settings.FirstOrDefault(x => x.Key == keyString); return(setting != null ? setting.Value : null); } }
public void ResetPassword(Guid userId, string newPassword) { using (var context = new InstantStoreDataContext()) { var user = context.Users.FirstOrDefault(u => u.Id == userId); user.Password = PasswordHash.PasswordHash.CreateHash(newPassword); context.SubmitChanges(); } }
public ActionResult Orders(char t = 'p', int o = 0, int c = 50) { var user = this.HttpContext.CurrentUser(); this.ViewData["MainMenuViewModel"] = MenuViewModelFactory.CreateAdminMenu(repository, ControlPanelPage.Orders); this.ViewData["SettingsViewModel"] = this.settingsViewModel; OrderStatus status; if (!statusMap.TryGetValue(t, out status)) { status = OrderStatus.Placed; } using (var context = new InstantStoreDataContext()) { Func <Order, bool> selector = (Order order) => (int)status == order.Status; Func <OrderUpdate, bool> orderSortDateSelector = (OrderUpdate update) => update.Status == (int)status; this.ViewData["OrdersTableViewModel"] = new TableViewModel { Header = new List <TableCellViewModel> { new TableCellViewModel(StringResource.user_HistoryListHeaderTime), new TableCellViewModel(StringResource.user_HistoryListHeaderUserName), new TableCellViewModel(StringResource.user_HistoryListHeaderItemCount), new TableCellViewModel(StringResource.user_HistoryListHeaderTotalPrice), new TableCellViewModel(StringResource.user_HistoryListHeaderProcessTime) }, Rows = context.Orders .Where(selector) .OrderByDescending(order => order.OrderUpdates .Where(orderSortDateSelector) .OrderByDescending(u => u.DateTime) .First().DateTime) .Skip(o) .Take(c) .Select(ConvertOrderToTableRow) .ToList(), RowClickAction = new NavigationLink("Order"), Pagination = new PaginationViewModel(c, o, context.Orders.Count(selector)) { Link = new NavigationLink("Orders", "Admin") { Parameters = new { t = t } } } }; this.ViewData["OrdersHeaderViewModel"] = new TabControlViewModel { Tabs = statusMap.Select(key => CreateOrderStatusHeader(key, t)).ToList() }; } return(this.View()); }
public static void RebuidCategoryTreeGroups(InstantStoreDataContext context, Guid updatedPageId) { Guid parentPageId = updatedPageId; // Walking up the tree rebuilding the group we just came from. while (parentPageId != Guid.Empty) { parentPageId = UpdateCategoryGropus(parentPageId, context) ?? Guid.Empty; } }
public void AddFeedback(Feedback feedback) { using (var context = new InstantStoreDataContext()) { feedback.Id = Guid.NewGuid(); feedback.Submitted = DateTime.Now; context.Feedbacks.InsertOnSubmit(feedback); context.SubmitChanges(); } }