/// <summary> /// Handles the UniGrid's OnAction event. /// </summary> /// <param name="actionName">Name of item (button) that throws event</param> /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param> protected void uniGrid_OnAction(string actionName, object actionArgument) { var id = ValidationHelper.GetInteger(actionArgument, 0); if (actionName == "edit") { URLHelper.Redirect(UIContextHelper.GetElementUrl("CMS.Ecommerce", "EditCustomersProperties", false, id)); } else if (actionName == "delete") { // Check module permissions if (!ECommerceContext.IsUserAuthorizedToModifyCustomer()) { RedirectToAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifyCustomers"); return; } // Get customer to be deleted var customer = CustomerInfoProvider.GetCustomerInfo(id); // Check customers dependencies if ((customer != null) && customer.Generalized.CheckDependencies()) { ShowError(ECommerceHelper.GetDependencyMessage(customer)); return; } // Delete CustomerInfo object from database CustomerInfoProvider.DeleteCustomerInfo(customer); UniGrid.ReloadData(); } }
/// <summary> /// Validates this step. /// </summary> public override bool IsValid() { // Check modify permissions if (ShoppingCartControl.CheckoutProcessType == CheckoutProcessEnum.CMSDeskOrderItems) { // Check 'ModifyOrders' permission if (!ECommerceContext.IsUserAuthorizedForPermission(EcommercePermissions.ORDERS_MODIFY)) { CMSPage.RedirectToAccessDenied(ModuleName.ECOMMERCE, "EcommerceModify OR ModifyOrders"); } } // Allow to go to the next step only if shopping cart contains some products bool IsValid = !ShoppingCart.IsEmpty; if (!IsValid) { HideCartContent(); } if (ShoppingCart.IsCreatedFromOrder) { IsValid = true; } if (!IsValid) { lblError.Text = GetString("ecommerce.error.insertsomeproducts"); } return(IsValid); }
public ActionResult Edit(User user) { if (ModelState.IsValid) { if (user.PhotoFile != null) { var folder = "~/Content/Users"; var file = string.Format("{0}.jpg", user.UserId); var response = FilesHelper.UploadPhoto(user.PhotoFile, folder, file); user.Photo = string.Format("{0}/{1}", folder, file); } var db2 = new ECommerceContext(); var currentUser = db2.Users.Find(user.UserId); //Find look ID if (currentUser.UserName != user.UserName) { UsersHelper.UpdateUserName(currentUser.UserName, user.UserName); } db2.Dispose(); db.Entry(user).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CityId = new SelectList(CombosHelper.GetCities(), "CityId", "Name", user.CityId); ViewBag.CompanyId = new SelectList(CombosHelper.GetCompanies(), "CompanyId", "Name", user.CompanyId); ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartments(), "DepartmentId", "Name", user.DepartmentId); return(View(user)); }
protected override void OnInit(EventArgs e) { base.OnInit(e); CMSContentPage.CheckSecurity(); // Check module permissions if (!ECommerceContext.IsUserAuthorizedForPermission("ReadProducts")) { RedirectToAccessDenied("CMS.Ecommerce", "EcommerceRead OR ReadProducts"); } SKUInfo sku = null; if (Node != null) { sku = SKUInfoProvider.GetSKUInfo(Node.NodeSKUID); } if ((sku != null) && (sku.SKUSiteID != SiteContext.CurrentSiteID) && ((sku.SKUSiteID != 0) || !ECommerceSettings.AllowGlobalProducts(SiteContext.CurrentSiteName))) { EditedObject = null; } productEditElem.ProductSaved += productEditElem_ProductSaved; string action = QueryHelper.GetString("action", string.Empty).ToLowerCSafe(); if (action == "newculture") { // Ensure breadcrumb for new culture version of product EnsureDocumentBreadcrumbs(PageBreadcrumbs, action: GetString("content.newcultureversiontitle")); } }
protected virtual ActionResult NotFound() { using (new Tracer()) { // TODO: Have the possiblity to have a E-Commerce specific 404 page for categories and products // string notFoundPageUrl = ECommerceContext.LocalizePath("/error-404"); PageModel pageModel; try { pageModel = ContentProvider.GetPageModel(notFoundPageUrl, WebRequestContext.Localization); } catch (DxaItemNotFoundException ex) { Log.Error(ex); throw new HttpException(404, ex.Message); } SetupViewData(pageModel); ViewModel model = EnrichModel(pageModel) ?? pageModel; Response.StatusCode = 404; return(View(pageModel)); } }
public static Response SaveChanges(ECommerceContext db) { try { db.SaveChanges(); return(new Response { Succeeded = true }); } catch (Exception ex) { var response = new Response { Succeeded = false }; if (ex.InnerException != null && ex.InnerException.InnerException != null && ex.InnerException.InnerException.Message.Contains("_Index")) { response.Message = "There are a record with the same value."; } else if (ex.InnerException != null && ex.InnerException.InnerException != null && ex.InnerException.InnerException.Message.Contains("REFERENCE")) { response.Message = "The record can't be deleted because it has related records."; } else { response.Message = ex.Message; } return(response); } }
static void InitializeDB() { using (ECommerceContext ctx = new ECommerceContext()) { ctx.Database.EnsureCreated(); } }
/// <summary> /// Validates this step. /// </summary> public override bool IsValid() { // Check modify permissions if (this.ShoppingCartControl.CheckoutProcessType == CheckoutProcessEnum.CMSDeskOrderItems) { // Check 'ModifyOrders' permission if (!ECommerceContext.IsUserAuthorizedForPermission("ModifyOrders")) { CMSEcommercePage.RedirectToCMSDeskAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifyOrders"); } } // Allow to go to the next step only if shopping cart contains some products bool IsValid = (ShoppingCartInfoObj.CartItems.Count > 0); if (!IsValid) { HideCartContentWhenEmpty(); } if (this.ShoppingCartInfoObj.IsCreatedFromOrder) { IsValid = true; } if (!IsValid) { lblError.Text = GetString("Ecommerce.Error.InsertSomeProducts"); } return(IsValid); }
/// <summary> /// Handles the UniGrid's OnAction event. /// </summary> /// <param name="actionName">Name of item (button) that throws event</param> /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param> protected void uniGrid_OnAction(string actionName, object actionArgument) { if (actionName == "edit") { URLHelper.Redirect("Customer_Edit_Frameset.aspx?customerid=" + Convert.ToString(actionArgument)); } else if (actionName == "delete") { int customerId = ValidationHelper.GetInteger(actionArgument, 0); // Check module permissions if (!ECommerceContext.IsUserAuthorizedToModifyCustomer()) { RedirectToAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifyCustomers"); return; } // Check customers dependencies if (CustomerInfoProvider.CheckDependencies(customerId)) { ShowError(GetString("Ecommerce.DeleteDisabled")); return; } // Delete CustomerInfo object from database CustomerInfoProvider.DeleteCustomerInfo(customerId); UniGrid.ReloadData(); } }
protected override void OnLoad(EventArgs e) { // Highlight menu button AddMenuButtonSelectScript("Customers", ""); // Initialize OK button btnOk.Click += delegate(object sender, EventArgs args) { // Check permissions if (!ECommerceContext.IsUserAuthorizedToModifyCustomer()) { RedirectToAccessDenied("CMS.Ecommerce", "ModifyCustomers OR EcommerceModify"); } // Create new customer int customerId = ucCustomerNew.Save(); // Redirect to customer edit if (customerId > 0) { URLHelper.Redirect(string.Format("Customer_Edit_Frameset.aspx?customerid={0}&saved=1", customerId)); } }; base.OnLoad(e); }
protected void btnGenerate_Click(object sender, EventArgs e) { // check 'EcommerceModify' permission if (!ECommerceContext.IsUserAuthorizedForPermission("ModifyOrders")) { RedirectToAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifyOrders"); } // Save updated order invoice number // order.OrderInvoiceNumber = txtInvoiceNumber.Text; order.SetValue("facture", txtInvoiceNumber.Text); OrderInfoProvider.SetOrderInfo(order); // Generate and display new invoice string invoice = OrderInfoProvider.GetInvoice(orderId); lblInvoice.Text = URLHelper.MakeLinksAbsolute(invoice); // Save new invoice order.OrderInvoice = invoice; OrderInfoProvider.SetOrderInfo(order); // Show message ShowChangesSaved(); }
public ProductServices(ILogger <ProductServices> logger, ECommerceContext appDb, IMapper mapper, IUploadServices uploadServices) { this.logger = logger; this.appDb = appDb; this.mapper = mapper; this.uploadServices = uploadServices; }
/// <summary> /// Get search path to find an appropriate CMS template page for current product. /// </summary> /// <param name="productSeoId"></param> /// <param name="product"></param> /// <returns></returns> protected IList <string> GetSearchPath(string productSeoId, IProduct product) { var searchPath = new List <string>(); var basePath = ECommerceContext.LocalizePath("/products/"); // SEO id // if (productSeoId != null) { searchPath.Add(basePath + productSeoId); } // Product ID // searchPath.Add(basePath + product.Id); // Product Categories // if (product.Categories != null) { foreach (var category in product.Categories) { searchPath.Add(basePath + category.Id); } } // Generic fallback product look&feel // searchPath.Add(basePath + "generic"); return(searchPath); }
public OrderServices(ECommerceContext appDb, ILogger <OrderServices> logger, IMapper mapper, IEmailSender emailSender) { this.logger = logger; this.appDb = appDb; this.mapper = mapper; this.emailSender = emailSender; }
/// <summary> /// Saves edited customer. /// </summary> public void Save() { // Check module permissions if (!ECommerceContext.IsUserAuthorizedToModifyCustomer()) { RedirectToAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifyCustomers"); } // Validate form and get error message string errorMessage = Validate(); if (string.IsNullOrEmpty(errorMessage)) { // Save when no error SaveData(); // Show message ShowChangesSaved(); } else { // Show error message ShowError(errorMessage); } }
public LoginModel(string u, string p, ECommerceContext context) { _context = context; this.username = u; this.password = p; this.status = TryLogin(); }
/// <summary> /// Handles the UniGrid's OnAction event. /// </summary> /// <param name="actionName">Name of item (button) that throws event</param> /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param> protected void uniGrid_OnAction(string actionName, object actionArgument) { if (actionName == "edit") { URLHelper.Redirect("Customer_Edit_Address_Edit.aspx?customerId=" + customerId + "&addressId=" + Convert.ToString(actionArgument)); } else if (actionName == "delete") { if (customerObj == null) { return; } if (!ECommerceContext.IsUserAuthorizedToModifyCustomer()) { RedirectToAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifyCustomers"); } int addressId = ValidationHelper.GetInteger(actionArgument, 0); // Check for the address dependences if (AddressInfoProvider.CheckDependencies(addressId)) { lblError.Visible = true; lblError.Text = GetString("Ecommerce.DeleteDisabled"); return; } // Delete AddressInfo object from database AddressInfoProvider.DeleteAddressInfo(addressId); } }
/// <summary> /// Sets data to database. /// </summary> protected void btnOK_Click(object sender, EventArgs e) { if (customerObj == null) { return; } if (!ECommerceContext.IsUserAuthorizedToModifyCustomer()) { RedirectToAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifyCustomers"); } if (customerId != 0) { string errorMessage = new Validator().NotEmpty(txtAddressLine1.Text, "Customer_Edit_Address_Edit.rqvLine") .NotEmpty(txtAddressCity.Text, "Customer_Edit_Address_Edit.rqvCity") .NotEmpty(txtAddressZip.Text, "Customer_Edit_Address_Edit.rqvZipCode") .NotEmpty(txtPersonalName.Text, "Customer_Edit_Address_Edit.rqvPersonalName").Result; // Check country presence if (errorMessage == "" && (ucCountrySelector.CountryID <= 0)) { errorMessage = GetString("countryselector.selectedcountryerr"); } if (errorMessage == "") { // Get object AddressInfo addressObj = AddressInfoProvider.GetAddressInfo(addressId); if (addressObj == null) { addressObj = new AddressInfo(); } addressObj.AddressIsBilling = chkAddressIsBilling.Checked; addressObj.AddressIsShipping = chkAddressIsShipping.Checked; addressObj.AddressZip = txtAddressZip.Text.Trim(); addressObj.AddressPhone = txtAddressDeliveryPhone.Text.Trim(); addressObj.AddressPersonalName = txtPersonalName.Text.Trim(); addressObj.AddressLine1 = txtAddressLine1.Text.Trim(); addressObj.AddressEnabled = chkAddressEnabled.Checked; addressObj.AddressLine2 = txtAddressLine2.Text.Trim(); addressObj.AddressCity = txtAddressCity.Text.Trim(); addressObj.AddressCountryID = ucCountrySelector.CountryID; addressObj.AddressStateID = ucCountrySelector.StateID; addressObj.AddressIsCompany = chkAddressIsCompany.Checked; addressObj.AddressName = AddressInfoProvider.GetAddressName(addressObj); addressObj.AddressCustomerID = customerId; AddressInfoProvider.SetAddressInfo(addressObj); URLHelper.Redirect("Customer_Edit_Address_Edit.aspx?customerId=" + customerId + "&addressId=" + Convert.ToString(addressObj.AddressID) + "&saved=1"); } else { lblError.Visible = true; lblError.Text = errorMessage; } } }
protected override void OnInit(EventArgs e) { base.OnInit(e); Save += btnOK_Click; CustomerID = QueryHelper.GetInteger("customerId", 0); AddressSelectorClientID = QueryHelper.GetString("selectorid", string.Empty); // Register check permissions EditForm.OnCheckPermissions += EditForm_OnCheckPermissions; // Before save event EditForm.OnBeforeSave += EditForm_OnBeforeSave; // On item validation event EditForm.OnItemValidation += EditForm_OnItemValidation; // Check edited objects site id CustomerInfo customerInfo = EditedObjectParent as CustomerInfo; if (customerInfo != null) { if (!ECommerceContext.CheckCustomerSiteID(customerInfo)) { EditedObject = null; } } // Check 'EcommerceRead' permission if (!ECommerceContext.IsUserAuthorizedForPermission("ReadCustomers")) { RedirectToAccessDenied("CMS.Ecommerce", "EcommerceRead OR ReadCustomers"); } }
public RolesController(RoleManager <IdentityRole> rolesController, UserManager <ApplicationUser> userManager , ECommerceContext context) { _rolesManager = rolesController; _userManager = userManager; _context = context; }
/// <summary> /// On BtnAdd click event. /// </summary> protected void BtnAdd_Click(object sender, EventArgs e) { // Check 'EcommerceModify' permission if (!ECommerceContext.IsUserAuthorizedForPermission("ModifyOrders")) { RedirectToAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifyOrders"); } string allUnits = null; string allSkuId = null; foreach (KeyValuePair <int, TextBox> item in quantityControls) { // Get params int skuId = item.Key; TextBox txtUnits = item.Value; // Get unit count int units = ValidationHelper.GetInteger(txtUnits.Text, 0); if (units > 0) { // Get product and localized name SKUInfo product = SKUInfoProvider.GetSKUInfo(skuId); if (product != null) { string skuName = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(product.SKUName)); // Abort inserting products to the shopping cart ifIf product has some product options if (!DataHelper.DataSourceIsEmpty(OptionCategoryInfoProvider.GetProductOptionCategories(skuId, true))) { // Show error message ShowError(string.Format(GetString("Order_Edit_AddItems.ProductOptionsRequired"), skuName)); return; } // If selected product is a donation if (product.SKUProductType == SKUProductTypeEnum.Donation) { // If donation is customizable if (product.SKUPrivateDonation || !((product.SKUMinPrice == product.SKUPrice) && (product.SKUMaxPrice == product.SKUPrice))) { // Show error message ShowError(string.Format(GetString("order_edit_additems.donationpropertiesrequired"), skuName)); return; } } // Create strings with SKU IDs and units separated by ';' allSkuId += skuId + ";"; allUnits += units + ";"; } } } // Close this modal window and refresh parent values in window CloseWindow(allSkuId, allUnits); }
/// <summary> /// Facets /// </summary> /// <param name="entity"></param> /// <param name="containerSize"></param> /// <returns></returns> public ActionResult Facets(EntityModel entity, int containerSize = 0) { SetupViewData(entity, containerSize); FacetsWidget widget = (FacetsWidget)entity; // Get facets // IProductQueryResult queryResult = null; if (widget.CategoryReference != null) { var category = ResolveCategory(widget.CategoryReference); queryResult = ECommerceContext.Client.QueryService.Query(new Api.Model.Query { Category = category }); } else { // Use category from page controller // queryResult = (IProductQueryResult)ECommerceContext.Get(ECommerceContext.QUERY_RESULT); } if (queryResult == null) { queryResult = GetResultFromPageTemplate(); } widget.FacetGroups = queryResult.FacetGroups.ToList(); return(View(entity.MvcData.ViewName, entity)); }
protected void radFollowing_CheckedChanged(object sender, EventArgs e) { if (mDiscountCouponInfoObj != null) { // Check permissions if (!ECommerceContext.IsUserAuthorizedToModifyDiscountCoupon(mDiscountCouponInfoObj)) { if (mDiscountCouponInfoObj.IsGlobal) { RedirectToAccessDenied(ModuleName.ECOMMERCE, EcommercePermissions.ECOMMERCE_MODIFYGLOBAL); } else { RedirectToAccessDenied(ModuleName.ECOMMERCE, "EcommerceModify OR ModifyDiscounts"); } } mDiscountCouponInfoObj.DiscountCouponIsExcluded = radExcept.Checked; // Set discount DiscountCouponInfoProvider.SetDiscountCouponInfo(mDiscountCouponInfoObj); // Show message ShowChangesSaved(); } }
/// <summary> /// Product Detail /// </summary> /// <param name="entity"></param> /// <param name="containerSize"></param> /// <returns></returns> public ActionResult ProductDetail(EntityModel entity, int containerSize = 0) { SetupViewData(entity, containerSize); ProductDetailWidget widget = (ProductDetailWidget)entity; if (widget.ProductReference != null) { string productId; if (widget.ProductReference.ProductRef != null) { productId = widget.ProductReference.ProductRef.ExternalId; } else { productId = widget.ProductReference.ProductId; } // Get product details from E-Commerce service // widget.Product = ECommerceContext.Client.DetailService.GetDetail(productId); // TODO: Add error handling when product is not found } else { // Use product from page controller // widget.Product = (IProduct)ECommerceContext.Get(ECommerceContext.PRODUCT); } return(View(entity.MvcData.ViewName, entity)); }
protected void CheckPermissions(object sender, EventArgs e) { if (!ECommerceContext.IsUserAuthorizedForPermission(EcommercePermissions.ORDERS_MODIFY)) { RedirectToAccessDenied(ModuleName.ECOMMERCE, "EcommerceModify OR ModifyOrders"); } }
/// <summary> /// Product Lister /// </summary> /// <param name="entity"></param> /// <param name="containerSize"></param> /// <returns></returns> public ActionResult ProductLister(EntityModel entity, int containerSize = 0) { SetupViewData(entity, containerSize); ProductListerWidget widget = (ProductListerWidget)entity; IProductQueryResult queryResult = null; if (widget.CategoryReference != null) { var category = ResolveCategory(widget.CategoryReference); queryResult = ECommerceContext.Client.QueryService.Query(new Api.Model.Query { Category = category }); } else { // Use category from page controller // queryResult = (IProductQueryResult)ECommerceContext.Get(ECommerceContext.QUERY_RESULT); } if (queryResult == null) { queryResult = GetResultFromPageTemplate(); } widget.Items = queryResult.Products.ToList(); this.ProcessListerNavigationLinks(widget, queryResult, (IList <FacetParameter>)ECommerceContext.Get(ECommerceContext.FACETS)); return(View(entity.MvcData.ViewName, entity)); }
/// <summary> /// Handles the UniGrid's OnAction event. /// </summary> /// <param name="actionName">Name of item (button) that throws event</param> /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param> protected void uniGrid_OnAction(string actionName, object actionArgument) { int addressId = ValidationHelper.GetInteger(actionArgument, 0); if (actionName == "edit") { URLHelper.Redirect("Customer_Edit_Address_Edit.aspx?customerId=" + customerObj.CustomerID + "&addressId=" + addressId); } else if (actionName == "delete") { if (!ECommerceContext.IsUserAuthorizedToModifyCustomer()) { RedirectToAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifyCustomers"); } var address = AddressInfoProvider.GetAddressInfo(addressId); // Check for the address dependencies if ((address != null) && address.Generalized.CheckDependencies()) { ShowError(ECommerceHelper.GetDependencyMessage(address)); return; } // Delete AddressInfo object from database AddressInfoProvider.DeleteAddressInfo(address); } }
/// <summary> /// Hides specific order action (edit, delete, ...) from unigrid, if it should be hidden. /// </summary> /// <param name="sender">Sender from unigrid's ExternalDataBound.</param> /// <param name="actionName">Name of action to show/hide.</param> private void ShowOrHideAction(object sender, string actionName) { string[] visibleActionsArray = VisibleActions.Split('|'); bool hideAction = true; // Determine, if action should be shown or hidden foreach (var action in visibleActionsArray) { if (action == actionName) { hideAction = false; } } // Do not hide only if user has permissions if (!hideAction && ECommerceContext.IsUserAuthorizedForPermission(EcommercePermissions.ORDERS_MODIFY)) { return; } // Hiding CMSGridActionButton btn = sender as CMSGridActionButton; if (btn != null) { btn.Visible = false; visibleActionsList.Remove(actionName); } }
protected override void OnPreInit(EventArgs e) { base.OnPreInit(e); var addressObj = EditedObject as AddressInfo; // Object is created if (addressObj == null) { EditForm.OnAfterDataLoad += EditForm_OnAfterDataLoad; } // Check customer and his site binding var customer = EditedObjectParent as CustomerInfo; if ((customer == null) || (!ECommerceContext.CheckCustomerSiteID(customer)) || ((addressObj != null) && (addressObj.AddressCustomerID != customer.CustomerID))) { EditedObject = null; } EditForm.OnBeforeSave += EditForm_OnBeforeSave; EditForm.OnItemValidation += EditForm_OnItemValidation; EditForm.OnCheckPermissions += EditForm_OnCheckPermissions; }
protected void CheckPermissions(object sender, EventArgs e) { if (!ECommerceContext.IsUserAuthorizedForPermission("ModifyOrders")) { RedirectToAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifyOrders"); } }