public void Entities_with_same_id_but_different_type_should_not_be_equal() { int id = 10; var p1 = new Product { Id = id }; var c1 = new Category { Id = id }; Assert.AreNotEqual(p1, c1, "Entities of different types should not be equal, even if they have the same id"); }
/// <summary> /// Delete category /// </summary> /// <param name="category">Category</param> public virtual void DeleteCategory(Category category) { if (category == null) throw new ArgumentNullException("category"); category.Deleted = true; UpdateCategory(category); }
public void Can_save_and_load_category() { var category = new Category { Name = "Books", Description = "Description 1", CategoryTemplateId = 1, MetaKeywords = "Meta keywords", MetaDescription = "Meta description", MetaTitle = "Meta title", ParentCategoryId = 2, PictureId = 3, PageSize = 4, AllowCustomersToSelectPageSize = true, PageSizeOptions = "4, 2, 8, 12", PriceRanges = "1-3;", ShowOnHomePage = false, IncludeInTopMenu = true, HasDiscountsApplied = true, Published = true, SubjectToAcl = true, LimitedToStores = true, Deleted = false, DisplayOrder = 5, CreatedOnUtc = new DateTime(2010, 01, 01), UpdatedOnUtc = new DateTime(2010, 01, 02), }; var fromDb = SaveAndLoadEntity(category); fromDb.ShouldNotBeNull(); fromDb.Name.ShouldEqual("Books"); fromDb.Description.ShouldEqual("Description 1"); fromDb.CategoryTemplateId.ShouldEqual(1); fromDb.MetaKeywords.ShouldEqual("Meta keywords"); fromDb.MetaDescription.ShouldEqual("Meta description"); fromDb.ParentCategoryId.ShouldEqual(2); fromDb.PictureId.ShouldEqual(3); fromDb.PageSize.ShouldEqual(4); fromDb.AllowCustomersToSelectPageSize.ShouldEqual(true); fromDb.PageSizeOptions.ShouldEqual("4, 2, 8, 12"); fromDb.PriceRanges.ShouldEqual("1-3;"); fromDb.ShowOnHomePage.ShouldEqual(false); fromDb.IncludeInTopMenu.ShouldEqual(true); fromDb.HasDiscountsApplied.ShouldEqual(true); fromDb.Published.ShouldEqual(true); fromDb.SubjectToAcl.ShouldEqual(true); fromDb.LimitedToStores.ShouldEqual(true); fromDb.Deleted.ShouldEqual(false); fromDb.DisplayOrder.ShouldEqual(5); fromDb.CreatedOnUtc.ShouldEqual(new DateTime(2010, 01, 01)); fromDb.UpdatedOnUtc.ShouldEqual(new DateTime(2010, 01, 02)); }
/// <summary> /// Delete category /// </summary> /// <param name="category">Category</param> public virtual void DeleteCategory(Category category) { if (category == null) throw new ArgumentNullException("category"); category.Deleted = true; UpdateCategory(category); //set a ParentCategory property of the children to 0 var subcategories = GetAllCategoriesByParentCategoryId(category.Id); foreach (var subcategory in subcategories) { subcategory.ParentCategoryId = 0; UpdateCategory(subcategory); } }
public void Can_save_and_load_category_with_productCategories() { var category = new Category { Name = "Books", Description = "Description 1", MetaKeywords = "Meta keywords", MetaDescription = "Meta description", MetaTitle = "Meta title", SeName = "SE name", ParentCategoryId = 2, PictureId = 3, PageSize = 4, AllowCustomersToSelectPageSize = true, PageSizeOptions = "4, 2, 8, 12", PriceRanges = "1-3;", ShowOnHomePage = false, Published = true, Deleted = false, DisplayOrder = 5, CreatedOnUtc = new DateTime(2010, 01, 01), UpdatedOnUtc = new DateTime(2010, 01, 02) }; category.ProductCategories.Add ( new ProductCategory { IsFeaturedProduct = true, DisplayOrder = 1, Product = new Product() { Name = "Name 1", Published = true, Deleted = false, CreatedOnUtc = new DateTime(2010, 01, 01), UpdatedOnUtc = new DateTime(2010, 01, 02) } } ); var fromDb = SaveAndLoadEntity(category); fromDb.ShouldNotBeNull(); fromDb.Name.ShouldEqual("Books"); fromDb.ProductCategories.ShouldNotBeNull(); (fromDb.ProductCategories.Count == 1).ShouldBeTrue(); fromDb.ProductCategories.First().IsFeaturedProduct.ShouldEqual(true); }
private IList<Category> GetCategoryBreadCrumb(Category category) { if (category == null) throw new ArgumentNullException("category"); var breadCrumb = new List<Category>(); while (category != null && //category is not null !category.Deleted && //category is not deleted category.Published) //category is published { breadCrumb.Add(category); category = _categoryService.GetCategoryById(category.ParentCategoryId); } breadCrumb.Reverse(); return breadCrumb; }
protected void SaveCategoryAcl(Category category, CategoryModel model) { var existingAclRecords = _aclService.GetAclRecords(category); var allCustomerRoles = _customerService.GetAllCustomerRoles(true); foreach (var customerRole in allCustomerRoles) { if (model.SelectedCustomerRoleIds != null && model.SelectedCustomerRoleIds.Contains(customerRole.Id)) { //new role if (existingAclRecords.Count(acl => acl.CustomerRoleId == customerRole.Id) == 0) _aclService.InsertAclRecord(category, customerRole.Id); } else { //removed role var aclRecordToDelete = existingAclRecords.FirstOrDefault(acl => acl.CustomerRoleId == customerRole.Id); if (aclRecordToDelete != null) _aclService.DeleteAclRecord(aclRecordToDelete); } } }
private void PrepareAclModel(CategoryModel model, Category category, bool excludeProperties) { if (model == null) throw new ArgumentNullException("model"); model.AvailableCustomerRoles = _customerService .GetAllCustomerRoles(true) .Select(cr => cr.ToModel()) .ToList(); if (!excludeProperties) { if (category != null) { model.SelectedCustomerRoleIds = _aclService.GetCustomerRoleIdsWithAccess(category); } else { model.SelectedCustomerRoleIds = new int[0]; } } }
public virtual void LoadSpecsFilters(Category category, ISpecificationAttributeService specificationAttributeService, IWebHelper webHelper, IWorkContext workContext) { if (category == null) throw new ArgumentNullException("category"); var alreadyFilteredOptions = GetAlreadyFilteredSpecs(specificationAttributeService, webHelper, workContext); var notFilteredOptions = GetNotFilteredSpecs(category.Id, specificationAttributeService, webHelper, workContext); if (alreadyFilteredOptions.Count > 0 || notFilteredOptions.Count > 0) { this.Enabled = true; this.AlreadyFilteredItems = alreadyFilteredOptions.ToList().Select(x => { var item = new SpecificationFilterItem(); item.SpecificationAttributeName = x.SpecificationAttributeName; item.SpecificationAttributeOptionName = x.SpecificationAttributeOptionName; return item; }).ToList(); this.NotFilteredItems = notFilteredOptions.ToList().Select(x => { var item = new SpecificationFilterItem(); item.SpecificationAttributeName = x.SpecificationAttributeName; item.SpecificationAttributeOptionName = x.SpecificationAttributeOptionName; //filter URL var alreadyFilteredOptionIds = GetAlreadyFilteredSpecOptionIds(webHelper); if (!alreadyFilteredOptionIds.Contains(x.SpecificationAttributeOptionId)) alreadyFilteredOptionIds.Add(x.SpecificationAttributeOptionId); string newQueryParam = GenerateFilteredSpecQueryParam(alreadyFilteredOptionIds); string filterUrl = webHelper.ModifyQueryString(webHelper.GetThisPageUrl(true), QUERYSTRINGPARAM + "=" + newQueryParam, null); filterUrl = ExcludeQueryStringParams(filterUrl, webHelper); item.FilterUrl = filterUrl; return item; }).ToList(); //remove filter URL string removeFilterUrl = webHelper.RemoveQueryString(webHelper.GetThisPageUrl(true), QUERYSTRINGPARAM); removeFilterUrl = ExcludeQueryStringParams(removeFilterUrl, webHelper); this.RemoveFilterUrl = removeFilterUrl; } else { this.Enabled = false; } }
/// <summary> /// Updates the category /// </summary> /// <param name="category">Category</param> public virtual void UpdateCategory(Category category) { if (category == null) throw new ArgumentNullException("category"); //validate category hierarchy var parentCategory = GetCategoryById(category.ParentCategoryId); while (parentCategory != null) { if (category.Id == parentCategory.Id) { category.ParentCategoryId = 0; break; } parentCategory = GetCategoryById(parentCategory.ParentCategoryId); } _categoryRepository.Update(category); //cache _cacheManager.RemoveByPattern(CATEGORIES_PATTERN_KEY); _cacheManager.RemoveByPattern(PRODUCTCATEGORIES_PATTERN_KEY); //event notification _eventPublisher.EntityUpdated(category); }
protected virtual void PrepareAclModel(CategoryModel model, Category category, bool excludeProperties) { if (model == null) throw new ArgumentNullException("model"); if (!excludeProperties && category != null) model.SelectedCustomerRoleIds = _aclService.GetCustomerRoleIdsWithAccess(category).ToList(); var allRoles = _customerService.GetAllCustomerRoles(true); foreach (var role in allRoles) { model.AvailableCustomerRoles.Add(new SelectListItem { Text = role.Name, Value = role.Id.ToString(), Selected = model.SelectedCustomerRoleIds.Contains(role.Id) }); } }
protected void UpdateLocales(Category category, CategoryModel model) { foreach (var localized in model.Locales) { _localizedEntityService.SaveLocalizedValue(category, x => x.Name, localized.Name, localized.LanguageId); _localizedEntityService.SaveLocalizedValue(category, x => x.Description, localized.Description, localized.LanguageId); _localizedEntityService.SaveLocalizedValue(category, x => x.MetaKeywords, localized.MetaKeywords, localized.LanguageId); _localizedEntityService.SaveLocalizedValue(category, x => x.MetaDescription, localized.MetaDescription, localized.LanguageId); _localizedEntityService.SaveLocalizedValue(category, x => x.MetaTitle, localized.MetaTitle, localized.LanguageId); //search engine name var seName = category.ValidateSeName(localized.SeName, localized.Name, false); _urlRecordService.SaveSlug(category, seName, localized.LanguageId); } }
protected virtual void PrepareAclModel(CategoryModel model, Category category, bool excludeProperties) { if (model == null) throw new ArgumentNullException("model"); model.AvailableCustomerRoles = _customerService .GetAllCustomerRoles(true) .Select(cr => cr.ToModel()) .ToList(); if (!excludeProperties) { if (category != null) { model.SelectedCustomerRoleIds = category.CustomerRoles.ToArray(); } } }
private Category ResolveCategory(string categoryName, Category parentCategory) { Category currentCategory = _categoryService.GetAllCategories(categoryName).FirstOrDefault(); if (currentCategory != null) return currentCategory; currentCategory = new Category { Name = categoryName, MetaTitle = categoryName, MetaDescription = categoryName, MetaKeywords = categoryName, AllowCustomersToSelectPageSize = true, HasDiscountsApplied = false, CategoryTemplateId = 1, //Description = categoryName, DisplayOrder = 1, IncludeInTopMenu = false, PageSize = 8, PageSizeOptions = "12,8,4", ParentCategoryId = parentCategory != null ? parentCategory.Id : 0, ShowOnHomePage = false, SubjectToAcl = false, LimitedToStores = false, Published = true, CreatedOnUtc = DateTime.UtcNow, UpdatedOnUtc = DateTime.UtcNow }; _categoryService.InsertCategory(currentCategory); _urlRecordService.SaveSlug(currentCategory, currentCategory.ValidateSeName(categoryName, categoryName, true), 0); return _categoryService.GetAllCategories(categoryName).First(); }
private ICollection<Category> GetC5ProductCategories(C5Product c5Product) { var categories = new List<Category>(); foreach (var categoryName in c5Product.CategoryName.Split(',')) { var existingCategories = _categoryService.GetAllCategories(categoryName, true); if (existingCategories.Count > 1) { foreach (var category in existingCategories) { _categoryService.DeleteCategory(category); } } if (existingCategories.Count > 0) { categories.Add(existingCategories.First()); } else { var category = new Category() { CreatedOnUtc = DateTime.UtcNow, UpdatedOnUtc = DateTime.UtcNow, Name = c5Product.CategoryName, Published = true }; _categoryService.InsertCategory(category); categories.Add(category); } } return categories; }
private ProductCategory CreateProductCategory(Product nopProduct, Category c5Category) { return new ProductCategory() { ProductId = nopProduct.Id, CategoryId = c5Category.Id, //use Category property (not CategoryId) because appropriate property is stored in it IsFeaturedProduct = false, DisplayOrder = 1 }; }
//---------------------------------------------------------------------------------------------------------------------------------------------------- ////////Make sure sale increments are: //////// consecutive //////// don't intersect //////// begin at 0 //////// end at 9,999,999 //////[NonAction] //////protected virtual Boolean IncrementsAreGood(AUSaleRecord record) //////{ ////// var increments = record.AUIncrementRecords.OrderBy(a => a.FromBidAmt); ////// int count = 0; ////// decimal lowamt = decimal.MaxValue; ////// decimal highamt = 0; ////// decimal previoustoamt = 0; ////// foreach (var increment in increments) ////// { ////// if (increment.FromBidAmt < lowamt) ////// { lowamt = increment.FromBidAmt;} ////// if (increment.ToBidAmt > highamt) ////// { highamt = increment.ToBidAmt;} ////// //must ensure each increment is well formed before doing intersection checks below ////// if (increment.ToBidAmt <= increment.FromBidAmt) ////// return false; ////// //make sure this increment is consecutive to last increment (oncrements ordered by From amt) ////// if (count == 0) ////// {previoustoamt = increment.ToBidAmt;} ////// else ////// if (increment.FromBidAmt != previoustoamt + 1 ) ////// {return false;} ////// else ////// {previoustoamt = increment.ToBidAmt;} ////// count += 1; ////// } ////// //increments must begin in 0 and end in 9,999,999 ////// if (lowamt != 0 || highamt != 9999999) ////// {return false;} ////// var increments2 = record.AUIncrementRecords.OrderBy(a => a.FromBidAmt); ////// count = 0; ////// int count2 = 0; ////// foreach (var increment in increments) ////// { ////// foreach (var increment2 in increments2) ////// { ////// if (((increment.FromBidAmt >= increment2.FromBidAmt && increment.FromBidAmt <= increment2.ToBidAmt) || ////// (increment.ToBidAmt <= increment2.ToBidAmt && increment.ToBidAmt >= increment2.FromBidAmt )) && ////// (count != count2)) ////// { return false; } ////// count2 += 1; ////// } ////// count2 = 0; ////// count += 1; ////// } ////// return true; //////} #endregion #region Methods //--------------------------------------------------------------------------------------------------------------------------------------------- ////////When a view is returned, it expects that an associated .cshtml file is in the same view folder ////////structure as the controller layout for that area (if no areas are in use, then there is only ////////1 view folder and 1 controller folder). The controller name will be the folder name in the views ////////folder, and the actionresult name will be the expected name of the .cshtml file. //------------------------------------------------------------------------------------------------------------------------------------------- ////////[NopHttpsRequirement(SslRequirement.No)] ////////public ActionResult Index() ////////{ //////// return View(); ////////} //--------------------------------------------------------------------------------------------------------------------------------------------- //////public ActionResult CreateUpdateConsignor(int ConsignorId = 0) //////{ ////// AUConsignorRecord consignor = new AUConsignorRecord(); ////// if (ConsignorId > 0) ////// { ////// consignor = _consignorRepo.GetById(ConsignorId); ////// } ////// //indicate if entity has a fee associated. This tells Consignor page not to show fees fields if already has fee (maintain through grid) ////// var fee = _consignorService.GetFeesForOneId(ConsignorId, "AUConsignor"); ////// //return View(consignment); //use with custome view engine ////// //return View("CreateUpdatePromoSlider"); ////// //return View("~/Views/PromoSlider/CreateUpdatePromoSlider.cshtml"); ////// return View("~/Views/AUConsignor/CreateUpdateConsignor.cshtml", consignor); //worked first time null ////// //return View("~/Plugins/Widgets.PromoSlider/Views/PromoSlider/CreateUpdatePromoSlider.cshtml", slider); //////} //--------------------------------------------------------------------------------------------------------------------------------------------------- ////////this post happens when you click 'Save' //////[HttpPost] //////public ActionResult CreateUpdateConsignor(AUConsignorRecord record) //////{ ////// if (ModelState.IsValid) ////// { ////// AUConsignorRecord consignor = _consignorRepo.GetById(record.AUConsignorID); ////// if (consignor == null) ////// { ////// var CurrentCustomer = _authenticationService.GetAuthenticatedCustomer(); ////// record.CreatedBy = CurrentCustomer.Username; ////// record.UpdatedBy = CurrentCustomer.Username; ////// record.CreatedOnDT = System.DateTime.UtcNow; ////// record.UpdatedOnDT = System.DateTime.UtcNow; ////// //Make updated by same as created by date for initial store ////// //record.UpdatedOnDT = System.DateTime.UtcNow; ////// record.UpdatedOnDT = record.CreatedOnDT; ////// _consignorRepo.Insert(record); ////// //store a blank fee at the highest level to make consignor fees easier/more consistent grid design ////// var fee = new AUFeesRecord(); ////// fee.AUEntityID = record.AUConsignorID; ////// fee.AUEntityType = "AUConsignor"; ////// fee.CommissionCanExceedReserveInd = false; ////// fee.ExpertisingFeeAmt = 0; ////// fee.FixedFeeAmt = 0; ////// fee.InsuranceSoldPct = 0; ////// fee.InsuranceUnsoldPct = 0; ////// fee.InterestOnAdvancePct = 0; ////// fee.MinCommissionMailSoldAmt = 0; ////// fee.MinCommissionMailUnsoldAmt = 0; ////// fee.MinCommissionPublicSoldAmt = 0; ////// fee.MinCommissionPublicUnsoldAmt = 0; ////// fee.MinimumConsignorTotalFeeAmt = 0; ////// fee.MiscFeeAmt = 0; ////// fee.SoldPct = 0; ////// fee.UnsoldPct = 0; ////// _feesRepo.Insert(fee); ////// SuccessNotification("Consignor Created Successfully - please add consignments and fees!"); ////// return RedirectToRoute(new ////// { ////// Action = "CreateUpdateConsignor", ////// Controller = "AUConsignor", ////// ConsignorId = record.AUConsignorID ////// }); ////// } ////// else ////// { ////// //use latest consignor record to update with most up-do-date data rather than stale record ////// consignor.Prefix = record.Prefix; ////// consignor.FirstName = record.FirstName; ////// consignor.MiddleName = record.MiddleName; ////// consignor.LastName = record.LastName; ////// consignor.CustomerID = record.CustomerID; ////// consignor.Suffix = record.Suffix; ////// consignor.WEMailID = record.WEMailID; ////// consignor.HEMailID = record.HEMailID; ////// consignor.EMailPrefCode = record.EMailPrefCode; ////// //consignor.CommissionCanExceedReserveInd = record.CommissionCanExceedReserveInd; ////// //consignor.SoldPct = record.SoldPct; ////// //consignor.UnsoldPct = record.UnsoldPct; ////// //consignor.InsuranceSoldPct = record.InsuranceSoldPct; ////// //consignor.InsuranceUnsoldPct = record.InsuranceUnsoldPct; ////// //consignor.MinCommissionPublicSoldAmt = record.MinCommissionPublicSoldAmt; ////// //consignor.MinCommissionPublicUnsoldAmt = record.MinCommissionPublicUnsoldAmt; ////// //consignor.MinCommissionMailSoldAmt = record.MinCommissionMailSoldAmt; ////// //consignor.MinCommissionMailUnsoldAmt = record.MinCommissionMailUnsoldAmt; ////// //consignor.FixedFeeAmt = record.FixedFeeAmt; ////// //consignor.MinimumConsignorTotalFeeAmt = record.MinimumConsignorTotalFeeAmt; ////// //consignor.InterestOnAdvancePct = record.InterestOnAdvancePct; ////// //consignor.MiscFeeAmt = record.MiscFeeAmt; ////// //consignor.MiscFeeAmt = record.MiscFeeAmt; ////// //consignor.MiscFeeType = record.MiscFeeType; ////// //consignor.ExpertisingFeeAmt = record.ExpertisingFeeAmt; ////// //consignor.CreatedOnDT = System.DateTime.UtcNow; --> don't overlay created info ////// //consignor.CreatedBy = CurrentCustomer.Username; ////// var CurrentCustomer = _authenticationService.GetAuthenticatedCustomer(); ////// consignor.UpdatedBy = CurrentCustomer.Username; ////// consignor.UpdatedOnDT = System.DateTime.UtcNow; ////// //this is how nop converts it back out ////// //consignor.CreatedOnDT = _dateTimeHelper.ConvertToUserTime(customer.CreatedOnUtc, DateTimeKind.Utc); ////// //public virtual DateTime CreatedOnDT { get; set; } ////// //public virtual string CreatedBy { get; set; } ////// //public virtual DateTime UpdatedOnDT { get; set; } ////// //public virtual string UpdatedBy { get; set; } ////// _consignorRepo.Update(consignor); ////// _cacheManager.Clear(); ////// SuccessNotification("Changed Saved!"); ////// //return View(consignment); //now with customer view engine ////// return View("~/Views/AUConsignor/CreateUpdateConsignor.cshtml", consignor); //not hit first time?? ////// //return View("~/Plugins/Widgets.PromoSlider/Views/PromoSlider/CreateUpdatePromoSlider.cshtml", slider); ////// } ////// } ////// else ////// { ////// return View(); ////// //return View("~/Views/PromoSlider/CreateUpdatePromoSlider.cshtml"); //not hit first time? ////// //return View("~/Plugins/Widgets.PromoSlider/Views/PromoSlider/CreateUpdatePromoSlider.cshtml"); ////// } //////} //---------------------------------------------------------------------------------------------------------------------------------------------- ////////TODO: GET RID OF THIS VIEW?? ////////public ActionResult CreateUpdateOneFees(int oneID = 0, string entityType = null) ////////{ //////// //AUFeesRecord fees = new AUFeesRecord(); //////// //if (oneID > 0 && entityType != null) //////// //{ //////// // fees = _consignorService.GetFeesForOneId(oneID, entityType); //////// //} //////// ViewBag.oneID = oneID; //////// ViewBag.entityType = entityType; //////// return View("~/Views/AUConsignor/CreateUpdateOneFees.cshtml"); ////////} //--------------------------------------------------------------------------------------------------------------------------------------------------- //////public ActionResult GetFeesList(int oneID = 0, string entityType = null) //////{ ////// //var consignments = _consignmentService.GetAllConsignments( ////// // consignorId: consignorID, ////// // consignmentId: 0, ////// // desc: null, ////// // pageIndex: 0, ////// // pageSize: 500); ////// var feeslist = new List<AUFeesRecord>(); ////// var allfees = _consignorService.GetFeesHierarchyForEntryPoint(oneID, entityType); ////// var gridModel = new DataSourceResult(); ////// //may be null if fees never created for consignor or if entries not created in hierachy ////// // if (allfees[0] != null) --fails on index if none found ////// //04/18/16 - fix order of fees list allfees = allfees.OrderBy(f => f.AUEntityType).ToList(); ////// allfees = allfees.OrderBy(f => f.DisplayOrder).ToList(); ////// if (allfees.Count > 0) ////// { ////// gridModel.Data = allfees.Select(x => new ////// { ////// AUFeesID = x.AUFeesID, ////// AUEntityType = x.AUEntityType, ////// AUEntityID = x.AUEntityID, ////// CommissionCanExceedReserveInd = x.CommissionCanExceedReserveInd, ////// SoldPct = x.SoldPct, ////// UnsoldPct = x.UnsoldPct, ////// InsuranceSoldPct = x.InsuranceSoldPct, ////// InsuranceUnsoldPct = x.InsuranceUnsoldPct, ////// MinCommissionPublicSoldAmt = x.MinCommissionPublicSoldAmt, ////// MinCommissionPublicUnsoldAmt = x.MinCommissionPublicUnsoldAmt, ////// MinCommissionMailSoldAmt = x.MinCommissionMailSoldAmt, ////// MinCommissionMailUnsoldAmt = x.MinCommissionMailUnsoldAmt, ////// FixedFeeAmt = x.FixedFeeAmt, ////// MinimumConsignorTotalFeeAmt = x.MinimumConsignorTotalFeeAmt, ////// InterestOnAdvancePct = x.InterestOnAdvancePct, ////// MiscFeeAmt = x.MiscFeeAmt, ////// MiscFeeType = x.MiscFeeType, ////// ExpertisingFeeAmt = x.ExpertisingFeeAmt ////// }); ////// //Total = consignments.TotalCount ////// } ////// //var gridModel = new DataSourceResult ////// //{ ////// // Data = allfees.Select(x => new ////// // { ////// // AUFeesID = x.AUFeesID, ////// // AUEntityType = x.AUEntityType, ////// // AUEntityID = x.AUEntityID, ////// // CommissionCanExceedReserveInd = x.CommissionCanExceedReserveInd, ////// // SoldPct = x.SoldPct, ////// // UnsoldPct = x.UnsoldPct, ////// // InsuranceSoldPct = x.InsuranceSoldPct, ////// // InsuranceUnsoldPct = x.InsuranceUnsoldPct, ////// // MinCommissionPublicSoldAmt = x.MinCommissionPublicSoldAmt, ////// // MinCommissionPublicUnsoldAmt = x.MinCommissionPublicUnsoldAmt, ////// // MinCommissionMailSoldAmt = x.MinCommissionMailSoldAmt, ////// // MinCommissionMailUnsoldAmt = x.MinCommissionMailUnsoldAmt, ////// // FixedFeeAmt = x.FixedFeeAmt, ////// // MinimumConsignorTotalFeeAmt = x.MinimumConsignorTotalFeeAmt, ////// // InterestOnAdvancePct = x.InterestOnAdvancePct, ////// // MiscFeeAmt = x.MiscFeeAmt, ////// // MiscFeeType = x.MiscFeeType, ////// // ExpertisingFeeAmt = x.ExpertisingFeeAmt ////// // }), ////// // //Total = consignments.TotalCount ////// //}; ////// return Json(gridModel); //////} //--------------------------------------------------------------------------------------------------------------------------------------------- ////////02/25/15 - comment for now ////////[HttpPost] ////////public ActionResult CreateUpdateOneFees(AUFeesRecord fees) ////////{ //////// var CurrentCustomer = _authenticationService.GetAuthenticatedCustomer(); //////// //session.CreatedBy = CurrentCustomer.Username; //////// //session.UpdatedBy = CurrentCustomer.Username; //////// //session.CreatedOnDT = System.DateTime.UtcNow; //////// //session.UpdatedOnDT = System.DateTime.UtcNow; //////// //var sale = _saleRepo.GetById(session.AUSaleID); //////// //sale.AUSessionRecords.Add(session); //////// //_saleRepo.Update(sale); //////// SuccessNotification("Consignor Fees Updated!", false); //////// return View("~/Views/AUConsignor/CreateUpdateOneFees.cshtml", fees); ////////} //------------------------------------------------------------------------------------------------------------------------------------------------------ //////public ActionResult CreateUpdateConsignment(int ConsignorId = 0, int ConsignmentId = 0) //////{ ////// //AUConsignmentRecord consignment = new AUConsignmentRecord() { ConsignmentDesc = "Test" }; ////// //AUConsignorRecord consignor = new AUConsignorRecord(); ////// AUCombConsignorConsignment combined = new AUCombConsignorConsignment(); ////// //string x = "not there"; ////// //string y = "not there"; ////// //if (RouteData.Values["ConsignmentId"] != null) ////// //{ ////// // x = RouteData.Values["ConsignmentId"].ToString(); ////// //} ////// //if (RouteData.DataTokens != null) ////// //{ ////// // y = RouteData.DataTokens.ToString(); ////// //} ////// if (ConsignmentId > 0) ////// { ////// combined.AUConsignmentRecord = _consignmentRepo.GetById(ConsignmentId); ////// //consignment = _consignmentRepo.GetById(ConsignmentId); ////// } ////// else ////// { ////// //need to do this to make sure model is valid for ADD ////// combined.AUConsignmentRecord = new AUConsignmentRecord(); ////// combined.AUConsignmentRecord.AUConsignmentID = 0; //set this because kick model invalid in POST otherwise ////// } ////// if (ConsignorId > 0) ////// { ////// combined.AUConsignorRecord = _consignorRepo.GetById(ConsignorId); ////// //consignor = _consignorRepo.GetById(ConsignorId); ////// //--AUConsignorConsignmentRecord testc = new AUConsignorConsignmentRecord(); ////// //--testc.AUConsignorID = ConsignorId; ////// // testc.AUConsignorID = consignor.AUConsignorID; ////// //testc.AUConsignmentID = r2.AUConsignmentID; ////// //testc.Term = "F**k"; ////// //--consignment.AUConsignorRecords.Add(testc); ////// //--combined.AUConsignmentRecord.AUConsignorRecords.Add(testc); ////// } ////// //return View(consignment); //use with custome view engine ////// //return View("CreateUpdatePromoSlider"); ////// //return View("~/Views/PromoSlider/CreateUpdatePromoSlider.cshtml"); ////// //last one that worked ////// //return View("~/Views/AUConsignor/CreateUpdateConsignment.cshtml", consignment); //worked first time null ////// return View("~/Views/AUConsignor/CreateUpdateConsignment.cshtml", combined); //worked first time null ////// //return View("~/Plugins/Widgets.PromoSlider/Views/PromoSlider/CreateUpdatePromoSlider.cshtml", slider); //////} //-------------------------------------------------------------------------------------------------------------------------------------------- //////[HttpPost] //////public ActionResult CreateUpdateConsignment(AUCombConsignorConsignment r2) //////{ ////// if (ModelState.IsValid) ////// { ////// AUConsignmentRecord consignment = _consignmentRepo.GetById(r2.AUConsignmentRecord.AUConsignmentID); ////// //DEBUG TO SEE IF r1 IS AVAILABLE ////// //TRY THIS WAY FIRST - NOT SURE BECAUSE MIGHT BE ABLE TO USE r1 ////// //MIGHT BE BEST ANYWAY TO ENSURE CORD STILL THERE ////// //no good !! could not instantiate ////// //AUConsignorRecord consignor = _consignorRepo.GetById(r1.AUConsignorID); ////// //string x = "not there"; ////// //if (RouteData.Values["ConsignmentId"] != null) ////// //{ ////// // x = RouteData.Values["ConsignmentId"].ToString(); ////// //} ////// //if (consignor == null) ////// //{ ////// // //place error handling here ////// //} ////// if (consignment == null) ////// { ////// //this worked but trying after insert ////// //AUConsignorConsignmentRecord testc = new AUConsignorConsignmentRecord(); ////// //testc.AUConsignorID = 1; ////// ////testc.AUConsignmentID = 1; ////// //testc.AUConsignmentID = r2.AUConsignmentID; //already known? ////// //testc.Term = "F**k"; ////// //r2.AUConsignorRecords.Add(testc); ////// //no good - can't update 2 entities ////// //r2.AUConsignmentRecord.CreatedOnDT = System.DateTime.UtcNow; ////// //r2.AUConsignmentRecord.UpdatedOnDT = System.DateTime.UtcNow; ////// //_combinedRepo.Insert(r2); ////// //try this first ////// var CurrentCustomer = _authenticationService.GetAuthenticatedCustomer(); ////// r2.AUConsignmentRecord.CreatedBy = CurrentCustomer.Username; ////// r2.AUConsignmentRecord.UpdatedBy = CurrentCustomer.Username; ////// r2.AUConsignmentRecord.CreatedOnDT = System.DateTime.UtcNow; ////// r2.AUConsignmentRecord.UpdatedOnDT = System.DateTime.UtcNow; ////// _consignmentRepo.Insert(r2.AUConsignmentRecord); ////// //try this second ////// //AUConsignmentRecord consignment2 = new AUConsignmentRecord() { ConsignmentDesc = "Test" }; ////// //consignment2.CreatedOnDT = System.DateTime.UtcNow; ////// //consignment2.UpdatedOnDT = System.DateTime.UtcNow; ////// //consignment2.ConsignmentDate = r2.AUConsignmentRecord.ConsignmentDate; ////// //consignment2.ConsignmentDesc = r2.AUConsignmentRecord.ConsignmentDesc; ////// //_consignmentRepo.Insert(consignment2); ////// /* ////// consignment.ConsignmentDate = r2.AUConsignmentRecord.ConsignmentDate; ////// consignment.ConsignmentDesc = r2.AUConsignmentRecord.ConsignmentDesc; ////// _consignmentRepo.Insert(consignment); ////// */ ////// //try 1 ////// AUConsignorConsignmentRecord testc = new AUConsignorConsignmentRecord(); ////// testc.AUConsignmentID = r2.AUConsignmentRecord.AUConsignmentID; ////// testc.AUConsignorID = r2.AUConsignorRecord.AUConsignorID; ////// testc.Term = "Help!"; ////// r2.AUConsignmentRecord.AUConsignorRecords.Add(testc); ////// _consignmentRepo.Update(r2.AUConsignmentRecord); ////// ////try 2 ////// //AUConsignorConsignmentRecord testc = new AUConsignorConsignmentRecord(); ////// //testc.AUConsignmentID = consignment2.AUConsignmentID; ////// //testc.AUConsignorID = r2.AUConsignorRecord.AUConsignorID; ////// //testc.Term = "Help!"; ////// //consignment2.AUConsignorRecords.Add(testc); ////// //_consignmentRepo.Update(consignment2); ////// //var toUpdate = r2.AUConsignorRecords.First(); ////// //toUpdate.AUConsignmentID = r2.AUConsignmentID; ////// //_consignmentRepo.Update(r2); ////// /* worked ////// //fails because trying to insert AUConsignor again ////// AUConsignorConsignmentRecord testc = new AUConsignorConsignmentRecord(); ////// //AUConsignmentRecord consignment2 = _consignmentRepo.GetById(r2.AUConsignmentID); ////// //testc.AUConsignorID = 1; WORKED ////// testc.AUConsignorID = consignor.AUConsignorID; ////// testc.AUConsignmentID = r2.AUConsignmentID; ////// testc.Term = "F**k"; ////// r2.AUConsignorRecords.Add(testc); ////// _consignmentRepo.Update(r2); ////// */ ////// //No Good - tried to insert AUConsignor again ////// //AUcc.AUConsignorID = 1; ////// //AUcc.AUConsignmentID = r2.AUConsignmentID; ////// //_consignorconsignmentRepo.Insert(AUcc); ////// //test shit out ////// //AUConsignorRecord c2 = new AUConsignorRecord(); ////// //c2.LastName = "consignor Last Name"; ////// //c2.AUConsignorID = 1; ////// //************************************** ////// //can only insert the same type passed in ////// //this is f*****g up consignment id for some reason ////// //************************************************* ////// //AUConsignmentRecord c2 = new AUConsignmentRecord(); ////// //c2.AUConsignmentID = 99; ////// //c2.ConsignmentDesc = "This is the first internally generated consignment"; ////// //_consignmentRepo.Insert(c2); ////// SuccessNotification("Consignment Created Successfully!"); ////// return RedirectToRoute(new ////// { ////// Action = "CreateUpdateConsignment", ////// Controller = "AUConsignor", ////// ConsignorId = r2.AUConsignorRecord.AUConsignorID, ////// ConsignmentId = r2.AUConsignmentRecord.AUConsignmentID ////// }); ////// } ////// else ////// { ////// //use latest data in consignment rather that stale R2 ////// var CurrentCustomer = _authenticationService.GetAuthenticatedCustomer(); ////// consignment.UpdatedBy = CurrentCustomer.Username; ////// consignment.UpdatedOnDT = System.DateTime.UtcNow; ////// consignment.ConsignmentDate = r2.AUConsignmentRecord.ConsignmentDate; ////// consignment.ConsignmentDesc = r2.AUConsignmentRecord.ConsignmentDesc; ////// //System.DateTime? cDate = null; ////// //try ////// //{ ////// // cDate = new DateTime(model.DateOfBirthYear.Value, model.DateOfBirthMonth.Value, model.DateOfBirthDay.Value); ////// //} ////// //catch { } ////// r2.AUConsignmentRecord.UpdatedOnDT = consignment.UpdatedOnDT; ////// r2.AUConsignmentRecord.UpdatedBy = consignment.UpdatedBy; ////// //test ////// //AUConsignorRecord c2 = new AUConsignorRecord(); ////// //c2.LastName = "consignor Last Name"; ////// //c2.AUConsignorID = 1; ////// //consignment.AUConsignorRecords.Add(c2); ////// //ViewBag.RowsAffected = db.Database.ExecuteSqlCommand("UPDATE Course SET Credits = Credits * {0}", multiplier); ////// _consignmentRepo.Update(consignment); ////// //can only insert the same type passed in ////// //AUConsignmentRecord c2 = new AUConsignmentRecord(); ////// //c2.AUConsignmentID = 99; ////// //c2.ConsignmentDesc = "This is the second updated description"; ////// //_consignmentRepo.Update(c2); ////// //AUConsignorRecord c2 = new AUConsignorRecord(); ////// //c2.LastName = "consignor New Last Name"; ////// //c2.AUConsignorID = 1; ////// //_consignmentRepo.Insert(); ////// _cacheManager.Clear(); ////// SuccessNotification("Changed Saved!"); ////// //return View(consignment); //now with customer view engine ////// return View("~/Views/AUConsignor/CreateUpdateConsignment.cshtml", r2); //not hit first time?? ////// //return View("~/Plugins/Widgets.PromoSlider/Views/PromoSlider/CreateUpdatePromoSlider.cshtml", slider); ////// } ////// } ////// else ////// { ////// //invalid model will show "default" error messages driven by record annotation/decorations ////// var errors = ModelState.Values.SelectMany(v => v.Errors); ////// return View("~/Views/AUConsignor/CreateUpdateConsignment.cshtml", r2); ////// //return View(); ////// //return View("~/Views/PromoSlider/CreateUpdatePromoSlider.cshtml"); //not hit first time? ////// //return View("~/Plugins/Widgets.PromoSlider/Views/PromoSlider/CreateUpdatePromoSlider.cshtml"); ////// } //////} //------------------------------------------------------------------------------------------------------------------------------------------------- //////public ActionResult CreateUpdateSale(int SaleId = 0) //////{ ////// AUSaleRecord sale = new AUSaleRecord(); ////// if (SaleId > 0) ////// { ////// sale = _saleRepo.GetById(SaleId); //this will have all the sessions and addresses!!!!! ////// } ////// ViewBag.SaleIsPublished = sale.SaleIsPublished; ////// return View("~/Views/AUConsignor/CreateUpdateSale.cshtml", sale); ////// // WORKS!! return View("CreateUpdateSale", sale); //This is what works with the view engine!!!! //////} //---------------------------------------------------------------------------------------------------------------------------------------------------- ////////this post happens when you click 'Save' //////[HttpPost] //////public ActionResult CreateUpdateSale(AUSaleRecord record, string save) //////{ ////// if (save.Equals("Award Sale")) //see http://stackoverflow.com/questions/19650345/mvc-razor-form-with-multiple-different-submit-buttons ////// { ////// _consignorService.AwardSale(record.AUSaleID, record.SaleStoreID); ////// //TempData["notice"] = "Sale Successfully Awarded"; --from google ////// SuccessNotification("Sale Awarded!!"); //seems to be nop admin convention ////// return RedirectToAction("CreateUpdateSale"); ////// } ////// //%%%%%the nav properties are gone, but the form values are there! reget the nav properties with getbyid before testing ////// if (ModelState.IsValid) ////// { ////// AUSaleRecord sale = _saleRepo.GetById(record.AUSaleID); ////// if (sale == null) ////// { ////// if (!record.SaleIsPublished) ////// { ////// _consignorService.InsertSale(record); ////// SuccessNotification("Sale Created Successfully!"); ////// return RedirectToRoute(new ////// { ////// Action = "CreateUpdateSale", ////// Controller = "AUConsignor", ////// SaleId = record.AUSaleID ////// }); ////// } ////// else ////// { ////// ErrorNotification("Insert of new sale not successful - trying to publish sale but something is wrong with your sale increments."); ////// return View("~/Views/AUConsignor/CreateUpdateSale.cshtml", record); ////// } ////// } ////// else //sale already exists so this will be an update. Use latest consignor record to update with most up-do-date data rather than stale record ////// { ////// sale.AUSaleNbr = record.AUSaleNbr; ////// sale.SaleTitle = record.SaleTitle; ////// sale.SaleDesc = record.SaleDesc; ////// sale.SaleStartDateTime = record.SaleStartDateTime; ////// sale.SaleEndDateTime = record.SaleEndDateTime; ////// sale.SaleStoreID = record.SaleStoreID; ////// sale.SaleIsAwarded = record.SaleIsAwarded; ////// sale.SaleType = record.SaleType; ////// sale.CreatedOnDT = System.DateTime.UtcNow; ////// sale.UpdatedOnDT = sale.CreatedOnDT; //make sure dates are the same on insert ////// //sale.UpdatedOnDT = System.DateTime.UtcNow; ////// var CurrentCustomer = _authenticationService.GetAuthenticatedCustomer(); ////// sale.UpdatedBy = CurrentCustomer.Username; ////// if (!record.SaleIsPublished) //not trying to publish sale so no further checking needed ////// { ////// //_consignorService.UpdateSale(sale,record); ////// // _cacheManager.Clear(); ////// sale.SaleIsPublished = record.SaleIsPublished; ////// _saleRepo.Update(sale); ////// SuccessNotification("Changes to Sale saved!"); ////// //return View(consignment); //now with customer view engine ////// return View("~/Views/AUConsignor/CreateUpdateSale.cshtml", sale); //BAD ////// } ////// else if (IncrementsAreGood(sale)) ////// { ////// //_consignorService.UpdateSale(sale,record); ////// sale.SaleIsPublished = record.SaleIsPublished; ////// _saleRepo.Update(sale); ////// //_cacheManager.Clear(); ////// SuccessNotification("Changes to Sale saved!"); ////// //return View(consignment); //now with customer view engine ////// return View("~/Views/AUConsignor/CreateUpdateSale.cshtml", sale); //BAD ////// } ////// else ////// { ////// ModelState.Remove("SaleIsPublished"); ////// sale.SaleIsPublished = false; ////// //ModelState.Remove("SaleIsPublished"); ////// ErrorNotification("Update sale not successful - trying to publish sale but something is wrong with your sale increments. Fix increments before trying to publish"); ////// return View("~/Views/AUConsignor/CreateUpdateSale.cshtml", sale); ////// } ////// } ////// } ////// else //model state is not valid ////// { ////// ErrorNotification("Invalid Model - Update not applied."); ////// return View("~/Views/AUConsignor/CreateUpdateSale.cshtml", record); ////// //return View(); ////// //return View("~/Views/PromoSlider/CreateUpdatePromoSlider.cshtml"); //not hit first time? ////// //return View("~/Plugins/Widgets.PromoSlider/Views/PromoSlider/CreateUpdatePromoSlider.cshtml"); ////// } //////} //---------------------------------------------------------------------------------------------------------------------------------------------------- //////public ActionResult CreateUpdateAddress(int addressId = 0, int saleId = 0) //////{ ////// AUCombAddress address = new AUCombAddress(); ////// address.AUAddressRecord = new AUAddressRecord(); //must instantiate the record within the record ////// if (addressId > 0) ////// { ////// address.AUAddressRecord = _addressRepo.GetById(addressId); ////// } ////// else ////// { ////// //need to do this to make sure model is valid for ADD ////// address.AUAddressRecord.AUAddressID = 0; ////// } ////// if (saleId > 0) ////// { ////// address.saleId = saleId; ////// } ////// else ////// { ////// //need to do this to make sure model is valid for ADD ////// address.saleId = saleId = 0; ////// } ////// //Populate Countries (see CustomerController) ////// address.AUAddressRecord.AvailableCountries.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Address.SelectCountry"), Value = "0" }); ////// foreach (var c in _countryService.GetAllCountries(true)) ////// { ////// address.AUAddressRecord.AvailableCountries.Add(new SelectListItem ////// { ////// Text = c.Name, ////// Value = c.Id.ToString(), ////// Selected = c.Id == address.AUAddressRecord.CountryId ////// }); ////// } ////// //Populate State/Province (see CustomerController). Had to take the ? away from Country ID as this statement complained ////// //that the parameter was invalid ////// var states = _stateProvinceService.GetStateProvincesByCountryId(address.AUAddressRecord.CountryId, false).ToList(); ////// if (states.Count > 0) ////// { ////// address.AUAddressRecord.AvailableStates.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Address.SelectState"), Value = "0" }); ////// foreach (var s in states) ////// { ////// address.AUAddressRecord.AvailableStates.Add(new SelectListItem { Text = s.Name, Value = s.Id.ToString(), Selected = (s.Id == address.AUAddressRecord.StateProvinceId) }); ////// } ////// } ////// else ////// { ////// bool anyCountrySelected = address.AUAddressRecord.AvailableCountries.Any(x => x.Selected); ////// address.AUAddressRecord.AvailableStates.Add(new SelectListItem ////// { ////// Text = _localizationService.GetResource(anyCountrySelected ? "Admin.Address.OtherNonUS" : "Admin.Address.SelectState"), ////// Value = "0" ////// }); ////// } ////// return View("~/Views/AUConsignor/CreateUpdateAddress.cshtml", address); //worked first time null //////} //------------------------------------------------------------------------------------------------------------------------------------- ////////this post happens when you click 'Save' //////[HttpPost] //////public ActionResult CreateUpdateAddress(AUCombAddress record) //////{ ////// if (ModelState.IsValid) ////// { ////// AUAddressRecord address = _addressRepo.GetById(record.AUAddressRecord.AUAddressID); ////// var CurrentCustomer = _authenticationService.GetAuthenticatedCustomer(); ////// record.AUAddressRecord.CreatedBy = CurrentCustomer.Username; ////// record.AUAddressRecord.UpdatedBy = CurrentCustomer.Username; ////// record.AUAddressRecord.CreatedOnDT = System.DateTime.UtcNow; ////// record.AUAddressRecord.UpdatedOnDT = System.DateTime.UtcNow; ////// if (address == null) ////// { ////// _addressRepo.Insert(record.AUAddressRecord); ////// SuccessNotification("Address Created Successfully!"); ////// return RedirectToRoute(new ////// { ////// Action = "CreateUpdateAddress", ////// Controller = "AUConsignor", ////// addressId = record.AUAddressRecord.AUAddressID, ////// saleId = record.saleId ////// }); ////// } ////// else ////// { ////// //use latest consignor record to update with most up-do-date data rather than stale record ////// address.Address1 = record.AUAddressRecord.Address1; ////// address.Address2 = record.AUAddressRecord.Address2; ////// address.AddressHtml = record.AUAddressRecord.AddressHtml; ////// address.City = record.AUAddressRecord.City; ////// address.CountryId = record.AUAddressRecord.CountryId; ////// address.StateProvinceId = record.AUAddressRecord.StateProvinceId; ////// address.ZipPostalCode = record.AUAddressRecord.ZipPostalCode; ////// //address.StateProvinceName = record.StateProvinceName; ////// //address.CountryName = record.CountryName; ////// //try this ////// //.ForMember(dest => dest.CountryName, mo => mo.MapFrom(src => src.Country != null ? src.Country.Name : null)) ////// address.UpdatedOnDT = record.AUAddressRecord.UpdatedOnDT; ////// address.UpdatedBy = record.AUAddressRecord.UpdatedBy; ////// //int id = NopContext.Current.User != null ? NopContext.Current.User.CustomerId : 0 ////// //NopContext.Current.User.CustomerId is no more present in version 3.0 ////// //this is how nop converts it back out ////// //consignor.CreatedOnDT = _dateTimeHelper.ConvertToUserTime(customer.CreatedOnUtc, DateTimeKind.Utc); ////// //public virtual DateTime CreatedOnDT { get; set; } ////// //public virtual string CreatedBy { get; set; } ////// //public virtual DateTime UpdatedOnDT { get; set; } ////// //public virtual string UpdatedBy { get; set; } ////// _addressRepo.Update(address); ////// // _cacheManager.Clear(); //took this out because it was killing the session ////// SuccessNotification("Changed Saved!"); ////// //return View("~/Views/AUConsignor/CreateUpdateAddress.cshtml", address); //not hit first time?? ////// //need redirect so can pick up country/state lists again ////// //if (record.saleId == 0) ////// //{ ////// return RedirectToRoute(new ////// { ////// Action = "CreateUpdateAddress", ////// Controller = "AUConsignor", ////// addressId = record.AUAddressRecord.AUAddressID, ////// saleId = record.saleId ////// }); ////// //} ////// //else ////// //{ ////// // return RedirectToRoute(new ////// // { ////// // Action = "CreateUpdateSale", ////// // Controller = "AUConsignor", ////// // saleId = record.saleId ////// // }); ////// //} ////// } ////// } ////// else ////// { ////// return View(); ////// //return View("~/Views/PromoSlider/CreateUpdatePromoSlider.cshtml"); //not hit first time? ////// //return View("~/Plugins/Widgets.PromoSlider/Views/PromoSlider/CreateUpdatePromoSlider.cshtml"); ////// } //////} //------------------------------------------------------------------------------------------------------------------------------- //////public ActionResult ListOneConsignments(int consignorID = 0) //////{ ////// AUConsignmentList consignments = new AUConsignmentList(); ////// consignments.searchAUConsignorID = consignorID; ////// return View("~/Views/AUConsignor/OneConsignorConsignments.cshtml", consignments); //////} //-------------------------------------------------------------------------------------------------------------------------------- ////////Consignor-consignments is an example of how to use an existing search to limit ////////consignments to one specific consignor. An example of how to use EF record definition ////////is in Sale-Sessions //////[HttpPost] //////public ActionResult ListXConsignments(int consignorID) //////{ ////// var consignments = _consignmentService.GetAllConsignments( ////// consignorId: consignorID, ////// consignmentId: 0, ////// desc: null, ////// pageIndex: 0, ////// pageSize: 500); ////// var gridModel = new DataSourceResult ////// { ////// Data = consignments.Select(x => new ////// { ////// AUConsignorID = x.AUConsignorRecords.First().AUConsignorID, ////// AUConsignmentID = x.AUConsignmentID, ////// ConsignmentDate = x.ConsignmentDate, ////// ConsignmentDesc = x.ConsignmentDesc ////// }), ////// Total = consignments.TotalCount ////// }; ////// return Json(gridModel); //////} //------------------------------------------------------------------------------------------------------------------------------ ////////kill this for now ////////public ActionResult ManageSaleSessions(int saleID = 0) ////////{ //////// AUSaleRecord sale = new AUSaleRecord(); //////// if (saleID > 0) //////// { //////// sale = _saleRepo.GetById(saleID); //this will have all the sessions and addresses!!!!! //////// } //////// return View("~/Views/AUConsignor/OneSaleSessions.cshtml",sale); ////////} //----------------------------------------------------------------------------------------------------------------------------- ////////display all lots associated to a sale for selection //////[ChildActionOnly] //////public ActionResult ManageSaleLots(int saleID = 0) //////{ ////// //AUSaleRecord increment = new AUIncrementRecord(); ////// //increment.AUSaleID = saleID; ////// //increment.AUIncrementID = 0; ////// ////%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ////// //session.AvailableAddresses.Add(new SelectListItem { Text = _localizationService.GetResource("Plugins.Misc.AUConsignor.SelectAddressMsg"), Value = "0" }); ////// //foreach (var c in _consignorService.GetAllAUAddresses()) ////// //{ ////// // session.AvailableAddresses.Add(new SelectListItem ////// // { ////// // Text = c.Address1 + ", " + c.Address2 + ", " + c.City, ////// // Value = c.AUAddressID.ToString(), ////// // Selected = c.AUAddressID == session.AUAddressID ////// // }); ////// //} ////// return View(); ////// //return View("~/Views/AUConsignor/ManageSaleIncrements.cshtml", increment); //////} //------------------------------------------------------------------------------------------------------------------------------- //////// [ChildActionOnly] ////// public ActionResult ManageSaleIncrements(int saleID = 0) ////// { ////// //put SaleIsPublished into ViewBag so view can hide the increment edit/delete buttons if published ////// var sale = _saleRepo.GetById(saleID); ////// ViewBag.SaleIsPublished = sale.SaleIsPublished; ////// AUIncrementRecord increment = new AUIncrementRecord(); ////// increment.AUSaleID = saleID; ////// increment.AUIncrementID = 0; ////// //session.AvailableAddresses.Add(new SelectListItem { Text = _localizationService.GetResource("Plugins.Misc.AUConsignor.SelectAddressMsg"), Value = "0" }); ////// //foreach (var c in _consignorService.GetAllAUAddresses()) ////// //{ ////// // session.AvailableAddresses.Add(new SelectListItem ////// // { ////// // Text = c.Address1 + ", " + c.Address2 + ", " + c.City, ////// // Value = c.AUAddressID.ToString(), ////// // Selected = c.AUAddressID == session.AUAddressID ////// // }); ////// //} ////// return View("~/Views/AUConsignor/ManageSaleIncrements.cshtml", increment); ////// } //////[ChildActionOnly] //////public ActionResult ManageSaleSessions(int saleID = 0) //////{ ////// AUSessionRecord session = new AUSessionRecord(); ////// session.AUSaleID = saleID; ////// session.AUSessionID = 0; ////// //%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ////// session.AvailableAddresses.Add(new SelectListItem { Text = _localizationService.GetResource("Plugins.Misc.AUConsignor.SelectAddressMsg"), Value = "0" }); ////// foreach (var c in _consignorService.GetAllAUAddresses()) ////// { ////// session.AvailableAddresses.Add(new SelectListItem ////// { ////// Text = c.Address1 + ", " + c.Address2 + ", " + c.City, ////// Value = c.AUAddressID.ToString(), ////// Selected = c.AUAddressID == session.AUAddressID ////// }); ////// } ////// return View("~/Views/AUConsignor/ManageSaleSessions.cshtml", session); //////} //////[HttpPost] //////public ActionResult CreateSaleSession(AUSessionRecord session) //////{ ////// if (!ModelState.IsValid) ////// { ////// ErrorNotification("something wrong with the model - notify admin"); ////// return View(); ////// } ////// //Recheck sale dates in case sale changed underneath session browser ////// var sale = _saleRepo.GetById(session.AUSaleID); ////// if (sale == null) ////// throw new NopException("Sale not found - please notify admin"); ////// if (session.SessionStartDateTime < sale.SaleStartDateTime || ////// session.SessionEndDateTime > sale.SaleEndDateTime || ////// session.SessionEndDateTime < sale.SaleStartDateTime || ////// session.SessionStartDateTime > sale.SaleEndDateTime) ////// { ////// ErrorNotification("Session dates must be within sale dates"); ////// return new NullJsonResult(); ////// } ////// var CurrentCustomer = _authenticationService.GetAuthenticatedCustomer(); ////// session.CreatedBy = CurrentCustomer.Username; ////// session.UpdatedBy = CurrentCustomer.Username; ////// session.CreatedOnDT = System.DateTime.UtcNow; ////// session.UpdatedOnDT = session.CreatedOnDT; ////// //TODO: CHECK SESSION DATES WITHIN SALE FROM-TO ////// sale.AUSessionRecords.Add(session); ////// _saleRepo.Update(sale); ////// SuccessNotification("Session Added!", false); ////// return new NullJsonResult(); //////} //////[HttpPost] //////public ActionResult GetSaleSessionsList(int saleId) //////{ ////// var sessions = _saleRepo.GetById(saleId).AUSessionRecords.OrderBy(x => x.SessionStartDateTime); ////// var gridModel = new DataSourceResult ////// { ////// Data = sessions.Select(x => new ////// { ////// AUSessionID = x.AUSessionID, ////// AUSaleID = x.AUSaleID, ////// SessionStartDateTime = _dateTimeHelper.ConvertToUserTime(x.SessionStartDateTime, DateTimeKind.Local), ////// SessionEndDateTime = _dateTimeHelper.ConvertToUserTime(x.SessionEndDateTime, DateTimeKind.Local), ////// SessionDescription = x.SessionDescription, ////// AUAddressID = x.AUAddressID, ////// AddressName = x.AUAddressRecord.Address1 + ", " + x.AUAddressRecord.Address2 + ", " + x.AUAddressRecord.City ////// }), ////// Total = sessions.Count() ////// }; ////// return Json(gridModel); //////} //////[HttpPost] //////public ActionResult CreateSaleIncrement(AUIncrementRecord increment) //this reference is injected by autofac (the repo is part of dbcontext) //////{ ////// var CurrentCustomer = _authenticationService.GetAuthenticatedCustomer(); ////// increment.CreatedBy = CurrentCustomer.Username; ////// increment.UpdatedBy = CurrentCustomer.Username; ////// increment.CreatedOnDT = System.DateTime.UtcNow; ////// increment.UpdatedOnDT = System.DateTime.UtcNow; ////// var sale = _saleRepo.GetById(increment.AUSaleID); ////// sale.AUIncrementRecords.Add(increment); ////// _saleRepo.Update(sale); ////// _eventPublisher.EntityInserted(increment); //publish event that increment inserted to flush cache in C:\Users\Nicholas\Documents\My Documents\NopCommerce\Plugins\Nop.Plugin.Misc.AUConsignor\Infrastructure\AUConsignorCacheEventConsumer.cs ////// SuccessNotification("Increment Added!", false); ////// return new NullJsonResult(); //////} ////////TODO: this function is redundant to the service in AUConsignor.Services //////[HttpPost] //////public ActionResult GetSaleIncrementsList(int saleId) //////{ ////// var increments = _saleRepo.GetById(saleId).AUIncrementRecords.OrderBy(x => x.FromBidAmt); ////// var gridModel = new DataSourceResult ////// { ////// Data = increments.Select(x => new ////// { ////// AUIncrementID = x.AUIncrementID, ////// AUSaleID = x.AUSaleID, ////// FromBidAmt = x.FromBidAmt, ////// ToBidAmt = x.ToBidAmt, ////// IncrementAmt = x.IncrementAmt ////// }), ////// Total = increments.Count() ////// }; ////// return Json(gridModel); //////} ////////Make sure sale session being added is within boundaries of sale from-to dates. Leave this as a server call in ////////case of concurrent access and held browser. TODO: determine if should move to browser for speed //////public JsonResult CheckSessionSaleDates(int AUSaleID, DateTime SessionStartDateTime, DateTime SessionEndDateTime) //////{ ////// //condition for user check ////// if (AUSaleID == 0) ////// throw new ArgumentNullException("AUSaleID"); ////// var sale = _saleRepo.GetById(AUSaleID); ////// if (sale == null) ////// { ////// throw new ArgumentException("AUSaleID not found"); ////// } ////// if (SessionStartDateTime < sale.SaleStartDateTime || SessionEndDateTime > sale.SaleEndDateTime) ////// { ////// return Json("BAD", JsonRequestBehavior.AllowGet); ////// } ////// return Json("GOOD", JsonRequestBehavior.AllowGet); //////} /////////TODO: DON'T THINK THIS IS USED //////[HttpPost] //////public ActionResult ListXSessions(int saleID) //////{ ////// var sessions = _saleRepo.GetById(saleID).AUSessionRecords.OrderBy(x => x.SessionStartDateTime); ////// //var consignments = _consignmentService.GetAllConsignments( ////// // consignorId: consignorID, ////// // consignmentId: 0, ////// // desc: null, ////// // pageIndex: 0, ////// // pageSize: 500); ////// var gridModel = new DataSourceResult ////// { ////// Data = sessions.Select(x => new ////// { ////// AUSaleID = x.AUSaleID, ////// AUSessionID = x.AUSessionID, ////// SessionStartDateTime = x.SessionStartDateTime, ////// SessionEndDateTime = x.SessionEndDateTime, ////// }), ////// Total = sessions.Count(n => n.AUSessionID > 0) //see http://stackoverflow.com/questions/3853010/get-item-count-of-a-list-using-linq ////// }; ////// return Json(gridModel); //////} //////public ActionResult ManageConsignments() //////{ ////// //return View(); ////// AUConsignmentList listsearch = new AUConsignmentList(); ////// //if (consignorID != 0) { listsearch.searchAUConsignorID = consignorID;} ////// return View("~/Views/AUConsignor/ManageConsignments.cshtml", listsearch); //not hit first time?? //////} //////[HttpPost] //////public ActionResult ListConsignments(DataSourceRequest command, AUConsignmentList model) //////{ ////// int consignmentid = 0; ////// //string firstname = "Test"; ////// //string lastname = ""; ////// int consignorid = model.searchAUConsignorID; ////// string desc = model.searchDesc; ////// var consignments = _consignmentService.GetAllConsignments( ////// consignorId: consignorid, ////// consignmentId: consignmentid, ////// desc: desc, ////// pageIndex: 0, ////// pageSize: 500); ////// //pageIndex: command.Page - 1, ////// //pageSize: command.PageSize); ////// //TODO: THIS WILL NEED TO BE CHANGED WHEN YOU IMPLEMENT MORE THAN ONE CONSIGNOR PER CONSIGNMENT ////// var gridModel = new DataSourceResult ////// { ////// Data = consignments.Select(x => new ////// { ////// Id = x.Id, ////// AUConsignorID = x.AUConsignorRecords.First().AUConsignorID, //TODO: make this a "primary" consignor select or coalesce all consignors ////// AUConsignmentID = x.AUConsignmentID, ////// ConsignmentDate = x.ConsignmentDate, ////// ConsignmentDesc = x.ConsignmentDesc ////// }), ////// Total = consignments.TotalCount ////// }; ////// return Json(gridModel); //////} ////////list lots //////public ActionResult LotIndex() //////{ ////// return RedirectToAction("ListLots"); //////} ////////copied from C:\Users\Nicholas\Documents\My Documents\NopCommerce\Presentation\Nop.Web\Administration\Controllers\ProductController.cs //////public ActionResult ListLots() //////{ ////// if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts)) ////// return View("~/Administration/Views/Security/AccessDenied.cshtml"); ////// var model = new AULotList(); ////// //a vendor should have access only to his products. Set the indicator in the model ////// model.IsLoggedInAsVendor = _workContext.CurrentVendor != null; ////// //categories ////// model.AvailableCategories.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" }); ////// var categories = _categoryService.GetAllCategories(showHidden: true); ////// foreach (var c in categories) ////// model.AvailableCategories.Add(new SelectListItem { Text = c.GetFormattedBreadCrumb(categories), Value = c.Id.ToString() }); ////// //NJM: Sales ////// model.AvailableSales.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" }); ////// var sales = _consignorService.GetAllSales( ////// saleId: 0, ////// saleNbr: null, ////// saleTitle: null, ////// pageIndex: 0, ////// pageSize: 2147483647); ////// foreach (var c in sales) ////// model.AvailableSales.Add(new SelectListItem { Text = c.AUSaleNbr, Value = c.AUSaleID.ToString() }); ////// //stores ////// model.AvailableStores.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" }); ////// foreach (var s in _storeService.GetAllStores()) ////// model.AvailableStores.Add(new SelectListItem { Text = s.Name, Value = s.Id.ToString() }); ////// //warehouses ////// model.AvailableWarehouses.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" }); ////// foreach (var wh in _shippingService.GetAllWarehouses()) ////// model.AvailableWarehouses.Add(new SelectListItem { Text = wh.Name, Value = wh.Id.ToString() }); ////// //product types ////// //NJM: Note ToSelectList is an extension method in Nop.Web.Framework ////// model.AvailableProductTypes = ProductType.SimpleProduct.ToSelectList(false).ToList(); ////// model.AvailableProductTypes.Insert(0, new SelectListItem { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" }); ////// //"published" property ////// //0 - all (according to "ShowHidden" parameter) ////// //1 - published only ////// //2 - unpublished only ////// model.AvailablePublishedOptions.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Catalog.Products.List.SearchPublished.All"), Value = "0" }); ////// model.AvailablePublishedOptions.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Catalog.Products.List.SearchPublished.PublishedOnly"), Value = "1" }); ////// model.AvailablePublishedOptions.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Catalog.Products.List.SearchPublished.UnpublishedOnly"), Value = "2" }); ////// return View("~/Views/AUConsignor/ManageLots.cshtml", model); ////// //return View("List.cshtml", model); //////} //////[HttpPost, ActionName("ListLots")] //////[FormValueRequired("go-to-product-by-sku")] //////public ActionResult GoToSku(AULotList model) //////{ ////// throw new NotImplementedException(); //need way to edit lot ////// //Console.Write("hit the button"); ////// //return new NullJsonResult(); //////} //////[HttpPost, ActionName("ListLots")] //////[FormValueRequired("exportexcel-all")] //////public ActionResult ExportExcelAll(AULotList model) //////{ ////// //throw new NotImplementedException("exportexcel-all button not implemented yet"); //need way to edit lot ////// //if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts)) ////// // return AccessDeniedView(); ////// ////a vendor should have access only to his products ////// //if (_workContext.CurrentVendor != null) ////// //{ ////// // model.SearchVendorId = _workContext.CurrentVendor.Id; ////// //} ////// var categoryIds = new List<int> { model.SearchCategoryId }; ////// //include subcategories ////// if (model.SearchIncludeSubCategories && model.SearchCategoryId > 0) ////// categoryIds.AddRange(GetChildCategoryIds(model.SearchCategoryId)); ////// //0 - all (according to "ShowHidden" parameter) ////// //1 - published only ////// //2 - unpublished only ////// bool? overridePublished = null; ////// if (model.SearchPublishedId == 1) ////// overridePublished = true; ////// else if (model.SearchPublishedId == 2) ////// overridePublished = false; ////// //var products = _productService.SearchProducts( ////// // categoryIds: categoryIds, ////// // manufacturerId: model.SearchManufacturerId, ////// // storeId: model.SearchStoreId, ////// // vendorId: model.SearchVendorId, ////// // warehouseId: model.SearchWarehouseId, ////// // productType: model.SearchProductTypeId > 0 ? (ProductType?)model.SearchProductTypeId : null, ////// // keywords: model.SearchProductName, ////// // showHidden: true, ////// // overridePublished: overridePublished ////// //); ////// var products = _consignorService.GetAllLots( ////// categoryIds: categoryIds, ////// saleId: model.SearchSaleId, ////// storeId: model.SearchStoreId, ////// warehouseId: model.SearchWarehouseId, ////// productType: model.SearchProductTypeId > 0 ? (ProductType?)model.SearchProductTypeId : null, ////// keywords: model.SearchProductName, ////// //pageIndex: command.Page - 1, ////// //pageSize: command.PageSize, ////// showHidden: true, ////// overridePublished: overridePublished ////// ); ////// try ////// { ////// byte[] bytes; ////// using (var stream = new MemoryStream()) ////// { ////// //_exportManager.ExportProductsToXlsx(stream, products); ////// _collectibleexportService.ExportPhilatelicProductsToXlsx(stream, products); ////// bytes = stream.ToArray(); ////// } ////// return File(bytes, "text/xls", "products.xlsx"); ////// } ////// catch (Exception exc) ////// { ////// ErrorNotification(exc); ////// return RedirectToAction("ListLots"); ////// } //////} //////[HttpPost] //////public ActionResult ExportExcelSelected(string selectedIds) //////{ ////// //if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts)) ////// // return AccessDeniedView(); ////// var products = new List<AUCombLotProc>(); ////// if (selectedIds != null) ////// { ////// var ids = selectedIds ////// .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) ////// .Select(x => Convert.ToInt32(x)) ////// .ToArray(); ////// products.AddRange(_consignorService.GetAllLots(productIds: ids)); ////// } ////// //a vendor should have access only to his products ////// if (_workContext.CurrentVendor != null) ////// { ////// products = products.Where(p => p.VendorId == _workContext.CurrentVendor.Id).ToList(); ////// } ////// byte[] bytes = null; ////// using (var stream = new MemoryStream()) ////// { ////// //_exportManager.ExportProductsToXlsx(stream, products); ////// _collectibleexportService.ExportPhilatelicProductsToXlsx(stream, products); ////// bytes = stream.ToArray(); ////// } ////// return File(bytes, "text/xls", "products.xlsx"); //////} //////[HttpPost, ActionName("ListLots")] //////[FormValueRequired("download-catalog-pdf")] //////public ActionResult DownloadCatalogAsPdf(AULotList model) //////{ ////// if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts)) ////// return View("~/Administration/Views/Security/AccessDenied.cshtml"); ////// //return AccessDeniedView(); ////// ////a vendor should have access only to his products ////// //if (_workContext.CurrentVendor != null) ////// //{ ////// // model.SearchVendorId = _workContext.CurrentVendor.Id; ////// //} ////// var categoryIds = new List<int> { model.SearchCategoryId }; ////// //include subcategories ////// if (model.SearchIncludeSubCategories && model.SearchCategoryId > 0) ////// categoryIds.AddRange(GetChildCategoryIds(model.SearchCategoryId)); ////// //0 - all (according to "ShowHidden" parameter) ////// //1 - published only ////// //2 - unpublished only ////// bool? overridePublished = null; ////// if (model.SearchPublishedId == 1) ////// overridePublished = true; ////// else if (model.SearchPublishedId == 2) ////// overridePublished = false; ////// //this will not conside exclude sale, as it general use for Manage Lots ////// var products = _consignorService.GetAllLots( ////// categoryIds: categoryIds, ////// saleId: model.SearchSaleId, ////// storeId: model.SearchStoreId, ////// warehouseId: model.SearchWarehouseId, ////// productType: model.SearchProductTypeId > 0 ? (ProductType?)model.SearchProductTypeId : null, ////// keywords: model.SearchProductName, ////// //pageIndex: command.Page - 1, ////// //pageSize: command.PageSize, ////// showHidden: true, ////// overridePublished: overridePublished ////// ); ////// try ////// { ////// byte[] bytes; ////// using (var stream = new MemoryStream()) ////// { ////// _philatelicpdfService.PrintProductsToPdf(stream, products); ////// bytes = stream.ToArray(); ////// } ////// return File(bytes, "application/pdf", "pdfcatalog.pdf"); ////// } ////// catch (Exception exc) ////// { ////// ErrorNotification(exc); ////// return RedirectToAction("ListLots"); ////// } //////} //////[HttpPost] //////public ActionResult LotList(DataSourceRequest command, AULotList model) //////{ ////// if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts)) ////// return View("~/Administration/Views/Security/AccessDenied.cshtml"); ////// //TODO: add in vendor logic for consignors to see their lots. See C:\Users\Nicholas\Documents\My Documents\NopCommerce\Presentation\Nop.Web\Administration\Controllers\ProductController.cs ProductList() ////// var categoryIds = new List<int> { model.SearchCategoryId }; ////// //include subcategories ////// if (model.SearchIncludeSubCategories && model.SearchCategoryId > 0) ////// categoryIds.AddRange(GetChildCategoryIds(model.SearchCategoryId)); ////// //0 - all (according to "ShowHidden" parameter) ////// //1 - published only ////// //2 - unpublished only ////// bool? overridePublished = null; ////// if (model.SearchPublishedId == 1) ////// overridePublished = true; ////// else if (model.SearchPublishedId == 2) ////// overridePublished = false; ////// //this will not conside exclude sale, as it general use for Manage Lots ////// var lots = _consignorService.GetAllLots( ////// categoryIds: categoryIds, ////// saleId: model.SearchSaleId, ////// storeId: model.SearchStoreId, ////// warehouseId: model.SearchWarehouseId, ////// productType: model.SearchProductTypeId > 0 ? (ProductType?)model.SearchProductTypeId : null, ////// keywords: model.SearchProductName, ////// pageIndex: command.Page - 1, ////// pageSize: command.PageSize, ////// showHidden: true, ////// overridePublished: overridePublished ////// ); ////// //int productid = 0; ////// //string firstname = "Test"; ////// //string lastname = ""; ////// //int productId = model.searchProductID; ////// //string searchname = model.searchName; ////// //%%%%%%%%%%%start cleaning here ////// //var lots = _consignorService.GetAllLots( ////// // //productId: productId, ////// // //searchname: searchname, ////// // pageIndex: 0, ////// // pageSize: 500); ////// //pageIndex: command.Page - 1, ////// //pageSize: command.PageSize); ////// //TODO: THIS WILL NEED TO BE CHANGED WHEN YOU IMPLEMENT MORE THAN ONE CONSIGNOR PER CONSIGNMENT ////// //%%%%%%%%%%lots is food - something wrong with the view ////// //var gridModel = new DataSourceResult ////// //{ ////// // Data = lots.Select(x => new ////// // { ////// // Id = x.Id, ////// // ProductID = x.ProductID, ////// // Name = x.Name, ////// // ShortDescription = x.ShortDescription, ////// // LotNbr = x.LotNbr, ////// // AUSaleID = x.AUSaleID, ////// // AUSaleNbr = x.AUSaleNbr, ////// // SaleTitle = x.SaleTitle ////// // }), ////// // Total = lots.TotalCount ////// //}; ////// var gridModel = new DataSourceResult(); ////// gridModel.Data = lots.Select(x => ////// { ////// var lotsModel = x.ToModel(); //ToModel uses EF mapper and is implemented as an Extension. Map definition is in Infrastructure\AutomapperStartupTask ////// lotsModel.Id = x.Id; ////// lotsModel.ProductID = x.ProductID; ////// lotsModel.AULotID = x.AULotID; ////// lotsModel.Name = x.Name; ////// lotsModel.ShortDescription = x.ShortDescription; ////// lotsModel.SKU = x.SKU; ////// lotsModel.LotNbr = x.LotNbr; ////// lotsModel.IsLotSold = x.IsLotSold; ////// lotsModel.AUSaleID = x.AUSaleID; ////// lotsModel.SaleIsActive = x.SaleIsActive; ////// lotsModel.AUSaleNbr = x.AUSaleNbr; ////// lotsModel.SaleTitle = x.SaleTitle; ////// //little hack here: ////// //ensure that product full descriptions are not returned ////// //otherwise, we can get the following error if products have too long descriptions: ////// //"Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property. " ////// //also it improves performance ////// //-->productModel.FullDescription = ""; ////// //picture ////// var defaultProductPicture = _pictureService.GetPicturesByProductId(x.ProductID, 1).FirstOrDefault(); ////// lotsModel.PictureThumbnailUrl = _pictureService.GetPictureUrl(defaultProductPicture, 75, true); ////// //product type ////// //productModel.ProductTypeName = x.ProductType.GetLocalizedEnum(_localizationService, _workContext); ////// //friendly stock qantity ////// //if a simple product AND "manage inventory" is "Track inventory", then display ////// //if (x.ProductType == ProductType.SimpleProduct && x.ManageInventoryMethod == ManageInventoryMethod.ManageStock) ////// // productModel.StockQuantityStr = x.GetTotalStockQuantity().ToString(); ////// return lotsModel; ////// }); ////// gridModel.Total = lots.TotalCount; ////// return Json(gridModel); //////} //////[HttpPost] //////public ActionResult ListSaleLots(DataSourceRequest command, AULotList model,int excludeSaleId, bool excludeSale) //////{ ////// if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts)) ////// return View("~/Administration/Views/Security/AccessDenied.cshtml"); ////// //0 - all (according to "ShowHidden" parameter) ////// //1 - published only ////// //2 - unpublished only ////// //bool? overridePublished = false; //show published and unpublished lots associated to the sale the sale ////// //should not happen ////// if (model.SearchSaleId == 0 && excludeSaleId != 0 && excludeSale == false ) ////// { ////// model.SearchSaleId = excludeSaleId; ////// } ////// //TODO: only show lots in the store ////// var lots = _consignorService.GetAllLots( ////// saleId: model.SearchSaleId, ////// pageIndex: command.Page - 1, ////// pageSize: command.PageSize, ////// showHidden: true, ////// excludeSale: excludeSale, ////// excludeSaleId: excludeSaleId ////// ); ////// //overridePublished: overridePublished, ////// //var lots = _consignorService.GetAllLots( ////// // categoryIds: categoryIds, ////// // saleId: model.SearchSaleId, ////// // storeId: model.SearchStoreId, ////// // warehouseId: model.SearchWarehouseId, ////// // productType: model.SearchProductTypeId > 0 ? (AUProductType?)model.SearchProductTypeId : null, ////// // keywords: model.SearchProductName, ////// // pageIndex: command.Page - 1, ////// // pageSize: command.PageSize, ////// // showHidden: true, ////// // overridePublished: overridePublished ////// //); ////// var gridModel = new DataSourceResult(); ////// gridModel.Data = lots.Select(x => ////// { ////// var lotsModel = x.ToModel(); //ToModel uses EF mapper and is implemented as an Extension. Map definition is in Infrastructure\AutomapperStartupTask ////// lotsModel.Id = x.Id; ////// lotsModel.ProductID = x.ProductID; ////// lotsModel.AULotID = x.AULotID; ////// lotsModel.Name = x.Name; ////// lotsModel.ShortDescription = x.ShortDescription; ////// lotsModel.SKU = x.SKU; ////// lotsModel.LotNbr = x.LotNbr; ////// lotsModel.IsLotSold = x.IsLotSold; ////// lotsModel.AUSaleID = x.AUSaleID; ////// lotsModel.AUSaleNbr = x.AUSaleNbr; ////// lotsModel.SaleTitle = x.SaleTitle; ////// //little hack here: ////// //ensure that product full descriptions are not returned ////// //otherwise, we can get the following error if products have too long descriptions: ////// //"Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property. " ////// //also it improves performance ////// //-->productModel.FullDescription = ""; ////// //picture ////// var defaultProductPicture = _pictureService.GetPicturesByProductId(x.ProductID, 1).FirstOrDefault(); ////// lotsModel.PictureThumbnailUrl = _pictureService.GetPictureUrl(defaultProductPicture, 75, true); ////// //product type ////// //productModel.ProductTypeName = x.ProductType.GetLocalizedEnum(_localizationService, _workContext); ////// //friendly stock qantity ////// //if a simple product AND "manage inventory" is "Track inventory", then display ////// //if (x.ProductType == ProductType.SimpleProduct && x.ManageInventoryMethod == ManageInventoryMethod.ManageStock) ////// // productModel.StockQuantityStr = x.GetTotalStockQuantity().ToString(); ////// return lotsModel; ////// }); ////// gridModel.Total = lots.TotalCount; ////// return Json(gridModel); //////} //////public ActionResult SaleProductAddPopup(int saleId) //////{ ////// if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts)) ////// return View("~/Administration/Views/Security/AccessDenied.cshtml"); ////// var model = new AULotList(); //using same search model as ManageLots ////// //a vendor should have access only to his products. Set the indicator in the model ////// model.IsLoggedInAsVendor = _workContext.CurrentVendor != null; ////// model.SaleId = saleId; ////// //categories ////// model.AvailableCategories.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" }); ////// var categories = _categoryService.GetAllCategories(showHidden: true); ////// foreach (var c in categories) ////// model.AvailableCategories.Add(new SelectListItem { Text = c.GetFormattedBreadCrumb(categories), Value = c.Id.ToString() }); ////// //NJM: Sales ////// model.AvailableSales.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" }); ////// var sales = _consignorService.GetAllSales( ////// saleId: saleId, ////// saleNbr: null, ////// saleTitle: null, ////// excludeSale: true, ////// pageIndex: 0, ////// pageSize: 2147483647); ////// foreach (var c in sales) ////// model.AvailableSales.Add(new SelectListItem { Text = c.AUSaleNbr, Value = c.AUSaleID.ToString() }); ////// //stores ////// model.AvailableStores.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" }); ////// foreach (var s in _storeService.GetAllStores()) ////// model.AvailableStores.Add(new SelectListItem { Text = s.Name, Value = s.Id.ToString() }); ////// //warehouses ////// model.AvailableWarehouses.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" }); ////// foreach (var wh in _shippingService.GetAllWarehouses()) ////// model.AvailableWarehouses.Add(new SelectListItem { Text = wh.Name, Value = wh.Id.ToString() }); ////// //product types ////// //NJM: Note ToSelectList is an extension method in Nop.Web.Framework ////// model.AvailableProductTypes = ProductType.SimpleProduct.ToSelectList(false).ToList(); ////// model.AvailableProductTypes.Insert(0, new SelectListItem { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" }); ////// //"published" property ////// //0 - all (according to "ShowHidden" parameter) ////// //1 - published only ////// //2 - unpublished only ////// model.AvailablePublishedOptions.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Catalog.Products.List.SearchPublished.All"), Value = "0" }); ////// model.AvailablePublishedOptions.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Catalog.Products.List.SearchPublished.PublishedOnly"), Value = "1" }); ////// model.AvailablePublishedOptions.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Catalog.Products.List.SearchPublished.UnpublishedOnly"), Value = "2" }); ////// return View("~/Views/AUConsignor/ManageSaleLotsPopup.cshtml", model); //////} ////// /// <summary> ////// /// WARNING - THIS CODE IS CURRENTLY NOT EXECUTED AS WE DO NOT ALLOW "ORPHAN" CONSIGNOR RECORDS. TODO: REMOVE THIS IF FULL TESTING REVEALS NOT NEEDED - ////// /// CURRENTLY FAILING BECAUSE MODEL IS SHOWN TO BE INVALID WHEN NON-ZERO VALIDATION (ANNOTATION) HIT FOR AUCONSIGNORRECORD ////// /// </summary> ////// /// <param name="consignorId"></param> ////// /// <returns></returns> //////// [HttpPost] ////// public ActionResult ConsignorCustomerDisassociate(int consignorId) ////// { ////// //TODO: Implement permissions ////// //if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts)) ////// // return AccessDeniedView(); ////// var consignor = _consignorService.GetConsignorById(consignorId); ////// if (consignor == null) ////// { ////// ErrorNotification("A major error occurred -consignor id sent to ConsignorCustomerDisassociate null. Please contact System Support"); ////// return RedirectToAction("ManageConsignors"); ////// } ////// consignor.CustomerID = 0; ////// _consignorRepo.Update(consignor); ////// //_cacheManager.Clear(); ////// SuccessNotification("Consignor disassociated from customer! Please associate to another customer asap"); ////// return View("~/Views/AUConsignor/CreateUpdateConsignor.cshtml", consignor); //not hit first time?? ////// } //////public ActionResult ConsignorCustomerSelectPopup(int consignorId) //////{ ////// //TODO: Permissions to associate Customer to Consignor ////// //if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts)) ////// // return View("~/Administration/Views/Security/AccessDenied.cshtml"); ////// var model = new AUCustomerList(); //using same search model as ManageLots ////// //TODO: a vendor should not be able to see the consignor info or set the customer. Add and Set the indicator in the model ////// model.IsLoggedInAsVendor = _workContext.CurrentVendor != null; ////// //TODO: POPULATE WITH PHONEENABLED, ////// model.PhoneEnabled = true; ////// model.ZipPostalCodeEnabled = true; ////// model.CompanyEnabled = true; ////// model.AUConsignorId = consignorId; ////// return View("~/Views/AUConsignor/ConsignorCustomerSelectPopup.cshtml", model); //////} //////[HttpPost] //////public ActionResult ConsignorCustomerSelectPopup(string selectedIds, int consignorId, string btnIdToRefresh, string frmIdToRefresh, AUCustomerList model) //////{ ////// //TODO: Implement permissions ////// //if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts)) ////// // return AccessDeniedView(); ////// var consignor = _consignorService.GetConsignorById(consignorId); ////// if (consignor == null || selectedIds == null) ////// { ////// ErrorNotification("A major error occurred -consignor id or selected ids from ConsignorCustomerSelectPopup null. Please contact System Support"); ////// return RedirectToAction("ManageConsignors"); ////// } ////// //TODO: Finish this - Need to get the lot info to ensure not already sold and unpublished ////// var ids = selectedIds ////// .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) ////// .Select(x => Convert.ToInt32(x)) ////// .ToArray(); ////// var customer = _consignorService.GetCustomerById(ids[0]); ////// if (customer == null) ////// { ////// ErrorNotification("A major error occurred - customer not found using vendor id from ConsignorCustomerSelectPopup null. Please contact System Support"); ////// return RedirectToAction("ManageConsignors"); ////// } ////// consignor.CustomerID = customer.Id; ////// _consignorRepo.Update(consignor); ////// SuccessNotification("Customer associated to Consignor!!"); //seems to be nop admin convention ////// ViewBag.RefreshPage = true; ////// ViewBag.btnId = btnIdToRefresh; ////// ViewBag.formId = frmIdToRefresh; ////// return View("~/Views/AUConsignor/ConsignorCustomerSelectPopup.cshtml", model); ////// //return RedirectToAction("ListLots"); //TODO FIX THIS //////} ////////Popup the sale selection popup window to copy increments from //////public ActionResult SaleIncrementCopyPopup(int saleId) //////{ ////// if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts)) ////// return View("~/Administration/Views/Security/AccessDenied.cshtml"); ////// var model = new AUSaleList(); //using same search model as ManageSales ////// //a vendor should have access only to his products. Set the indicator in the model ////// //model.IsLoggedInAsVendor = _workContext.CurrentVendor != null; ////// model.SaleId = saleId; ////// //Populate Sales ////// //don't allow select all model.AvailableSales.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" }); ////// var sales = _consignorService.GetAllSales( ////// saleId: saleId, ////// saleNbr: null, ////// saleTitle: null, ////// excludeSale: true, ////// pageIndex: 0, ////// pageSize: 2147483647); ////// foreach (var c in sales) ////// model.AvailableSales.Add(new SelectListItem { Text = c.SaleTitle, Value = c.AUSaleID.ToString() }); ////// return View("~/Views/AUConsignor/SaleIncrementCopyPopup.cshtml", model); //////} //////[HttpPost] //////public ActionResult SaleProductAddPopup(string selectedIds, int saleId, string btnIdToRefresh, string frmIdToRefresh, AULotList model) //////{ ////// //TODO: Implement permissions ////// //if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts)) ////// // return AccessDeniedView(); ////// var sale = _consignorService.GetSaleById(saleId); ////// if (sale == null) ////// { ////// ErrorNotification("A major error occurred -sale id from SaleProductAddPopup not found. Please contact System Support"); ////// return RedirectToAction("ManageSales"); ////// } ////// //TODO: Finish this - Need to get the lot info to ensure not already sold and unpublished ////// var lots = new List<AULotRecord>(); ////// if (selectedIds != null) ////// { ////// lots.AddRange(_consignorService.GetLotsByPids(selectedIds)); ////// } ////// foreach (var l in lots) ////// { ////// var sl = l.AUSaleRecords.FirstOrDefault(x => x.AUSaleID == sale.AUSaleID); ////// if (sl == null) //Sale exists but the junction AUSaleLot record doesn't ////// { ////// var saleLot = new AUSaleLotRecord ////// { ////// AUSaleID = sale.AUSaleID, ////// AULotID = l.AULotID, ////// LotNbr = 0, ////// SaleIsActive = sale.SaleIsActive, //pull this indicator from the Sale record - don't load from spreadsheet ////// DisplayOrder = 0 ////// }; ////// _consignorService.InsertSaleLot(saleLot); ////// } ////// //else //Sale exists and the junction AUSaleLot record does as well, so update it ////// //{ ////// // sl.AUSaleID = sale.AUSaleID; ////// // sl.AULotID = lot.AULotID; ////// // sl.LotNbr = LotNbr; ////// // sl.SaleIsActive = sale.SaleIsActive; ////// // sl.DisplayOrder = DisplayOrder; ////// // _consignorService.UpdateSaleLot(sl); ////// //} ////// } ////// ////a vendor should have access only to his products ////// //if (_workContext.CurrentVendor != null) ////// //{ ////// // products = products.Where(p => p.VendorId == _workContext.CurrentVendor.Id).ToList(); ////// //} ////// //_consignorService.PublishSelectedProducts(products); ////// SuccessNotification("Lots were associated to sale!!"); //seems to be nop admin convention ////// ViewBag.RefreshPage = true; ////// ViewBag.btnId = btnIdToRefresh; ////// ViewBag.formId = frmIdToRefresh; ////// return View("~/Views/AUConsignor/ManageSaleLotsPopup.cshtml", model); ////// //return RedirectToAction("ListLots"); //TODO FIX THIS //////} //////[HttpPost] //////public ActionResult CopySaleIncementsToSale(int selectedSaleId, int saleId, string btnIdToRefresh, string frmIdToRefresh, AUSaleList model) //////{ ////// //TODO: Implement permissions ////// //if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts)) ////// // return AccessDeniedView(); ////// var salefrom = _consignorService.GetSaleById(selectedSaleId); ////// if (salefrom == null) ////// { ////// ErrorNotification("A major error occurred -sale from id from CopySaleIncementsToSale popup not found. Please contact System Support"); ////// return RedirectToAction("ManageSales"); //TODO FIX THIS to alert majorerror ////// } ////// var saleto = _consignorService.GetSaleById(saleId); //TODO: why using service to get this record. ////// if (saleto == null) ////// { ////// ErrorNotification("A major error occurred -saleto id from CopySaleIncementsToSale popup not found. Please contact System Support"); ////// return RedirectToAction("ManageSales"); //TODO FIX THIS to alert majorerror ////// } ////// //changed so not walking the sale ////// var increments = saleto.AUIncrementRecords; ////// // consignor = _consignorRepo.GetById(ConsignorId); ////// //doesn't work - eats itself so second iteration fails ////// //foreach (var i in increments) ////// //{ ////// // var inc = _incrementRepo.GetById(i.AUIncrementID); ////// // _incrementRepo.Delete(inc); ////// //} ////// while (1 == 1) ////// { ////// var inc = increments.FirstOrDefault(); ////// if (inc != null) ////// { ////// _incrementRepo.Delete(inc); //these hit db right away ////// } ////// else ////// { ////// break; ////// } ////// } ////// //saleto.AUIncrementRecords.Clear(); ////// //_saleRepo.Update(saleto); ////// foreach (var incf in salefrom.AUIncrementRecords) ////// { ////// var newinc = new AUIncrementRecord(); ////// var sale = _saleRepo.GetById(saleto.AUSaleID); ////// newinc.AUSaleID = saleto.AUSaleID; //change forein key to new sale; ////// newinc.CreatedBy = "Test created by"; ////// //newinc.createdon ////// newinc.FromBidAmt = incf.FromBidAmt; ////// newinc.ToBidAmt = incf.ToBidAmt; ////// newinc.IncrementAmt = incf.IncrementAmt; ////// newinc.CreatedBy = "Test"; ////// newinc.UpdatedBy = "Test"; ////// newinc.CreatedOnDT = System.DateTime.UtcNow; ////// newinc.UpdatedOnDT = System.DateTime.UtcNow; ////// saleto.AUIncrementRecords.Add(newinc); ////// // saleto.AUIncrementRecords.Add(newinc); ////// // _saleRepo.Update(saleto); ////// // _incrementRepo.Insert(newinc); No Work - not null key??? ////// } ////// _saleRepo.Update(saleto); //record add above does not hit db until this ////// ////a vendor should have access only to his products ////// //if (_workContext.CurrentVendor != null) ////// //{ ////// // products = products.Where(p => p.VendorId == _workContext.CurrentVendor.Id).ToList(); ////// //} ////// //_consignorService.PublishSelectedProducts(products); ////// SuccessNotification("Increments were associated to sale!!"); //seems to be nop admin convention ////// ViewBag.RefreshPage = true; ////// ViewBag.btnId = btnIdToRefresh; //button to click (btnRefreshIncrements) ////// ViewBag.formId = frmIdToRefresh; //form to open (sale-form) ////// return View("~/Views/AUConsignor/SaleIncrementCopyPopup.cshtml", model); ////// //return RedirectToAction("ListLots"); //TODO FIX THIS //////} ////////[HttpPost] grid is not posting ////////the grid passes in fields in the row schema as well as the form model ////////the grid schema can containmore fields than are displayed in the columns ////////AULotID comes from the schema ////////AUSaleID comes from the model //////public ActionResult RemoveLotFromSale(int AULotID, AUSaleRecord model) //////{ ////// //TODO: AUTHORIZE ////// //if (!_permissionService.Authorize(StandardPermissionProvider.ManageCategories)) ////// // return AccessDeniedView(); ////// _consignorService.DeleteSaleLotByLotId(AULotID, model.AUSaleID); ////// //if (productCategory == null) ////// // throw new ArgumentException("No product category mapping found with the specified id"); ////// ////var categoryId = productCategory.CategoryId; ////// //_categoryService.DeleteProductCategory(productCategory); ////// return new NullJsonResult(); //////} //////public ActionResult DeleteFees(string btnIdToRefresh, string frmIdToRefresh, AUFeesRecord model) //////{ ////// //TODO: AUTHORIZE ////// //if (!_permissionService.Authorize(StandardPermissionProvider.ManageCategories)) ////// // return AccessDeniedView(); ////// var fee = _feesRepo.GetById(model.AUFeesID); ////// if (fee != null) //should not happen once you start hiding the inherit button on an inherited fee ////// { ////// _feesRepo.Delete(fee); ////// ViewBag.RefreshPage = true; ////// ViewBag.btnId = btnIdToRefresh; ////// ViewBag.formId = frmIdToRefresh; ////// } ////// return new NullJsonResult(); //////} //////public ActionResult InheritFees(AUFeesRecord model) //////{ ////// //TODO: AUTHORIZE ////// //if (!_permissionService.Authorize(StandardPermissionProvider.ManageCategories)) ////// // return AccessDeniedView(); ////// var fee = _feesRepo.GetById(model.AUFeesID); ////// _feesRepo.Delete(fee); ////// return new NullJsonResult(); //////} //////[HttpPost] //////public ActionResult CreateUpdateFees(AUFeesRecord model) //////{ ////// //TODO: Implement permissions across all actions ////// //if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts)) ////// // return AccessDeniedView(); ////// //var productCategory = _categoryService.GetProductCategoryById(model.Id); ////// //if (productCategory == null) ////// // throw new ArgumentException("No product category mapping found with the specified id"); ////// string feetype = ""; ////// var fee = new AUFeesRecord(); ////// if (model.AUFeesID > 0) ////// { ////// fee = _feesRepo.GetById(model.AUFeesID); //TODO: push into service ////// } ////// else ////// { ////// //Make sure you don't carry the Inherited indicator (I) into the database ////// feetype = model.AUEntityType; ////// if (model.AUEntityType == "AUConsignment(I)") ////// { ////// feetype = "AUConsignment"; ////// } ////// else if (model.AUEntityType == "AULot(I)") ////// { ////// feetype = "AULot"; ////// } ////// fee.AUEntityType = feetype; ////// fee.AUEntityID = model.AUEntityID; ////// //Hack - force in the Order here for displaying ////// if (feetype == "AUConsignor") ////// { ////// fee.DisplayOrder = 0; ////// } ////// else if (feetype == "AUConsignment") ////// { ////// fee.DisplayOrder = 2; ////// } ////// else if (feetype == "AULot") ////// { ////// fee.DisplayOrder = 3; ////// } ////// } ////// fee.CommissionCanExceedReserveInd = model.CommissionCanExceedReserveInd; ////// fee.ExpertisingFeeAmt = model.ExpertisingFeeAmt; ////// fee.FixedFeeAmt = model.FixedFeeAmt; ////// fee.InsuranceSoldPct = model.InsuranceSoldPct; ////// fee.InsuranceUnsoldPct = model.InsuranceUnsoldPct; ////// fee.InterestOnAdvancePct = model.InterestOnAdvancePct; ////// fee.MinCommissionMailSoldAmt = model.MinCommissionMailSoldAmt; ////// fee.MinCommissionMailUnsoldAmt = model.MinCommissionMailUnsoldAmt; ////// fee.MinCommissionPublicSoldAmt = model.MinCommissionPublicSoldAmt; ////// fee.MinCommissionPublicUnsoldAmt = model.MinCommissionPublicUnsoldAmt; ////// fee.MinimumConsignorTotalFeeAmt = model.MinimumConsignorTotalFeeAmt; ////// fee.MiscFeeAmt = model.MiscFeeAmt; ////// fee.SoldPct = model.SoldPct; ////// fee.UnsoldPct = model.UnsoldPct; ////// if (model.AUFeesID > 0) ////// { ////// _feesRepo.Update(fee); //TODO: push into service ////// } ////// else ////// { ////// _feesRepo.Insert(fee); ////// } ////// return new NullJsonResult(); //////} //////// [HttpPost] grid is not posting so signature can't be post ////////form passes fields in the grid row schema as well as the form model ////////the grid schema can contain more fields than are displayed in the columns ////////AULotID comes from the schema ////////AUSaleID comes from the model //////public ActionResult DeleteSaleIncrement(int AUIncrementID) //////{ ////// //TODO: AUTHORIZE ////// //if (!_permissionService.Authorize(StandardPermissionProvider.ManageCategories)) ////// // return AccessDeniedView(); ////// _consignorService.DeleteIncrementById(AUIncrementID); ////// //if (productCategory == null) ////// // throw new ArgumentException("No product category mapping found with the specified id"); ////// ////var categoryId = productCategory.CategoryId; ////// //_categoryService.DeleteProductCategory(productCategory); ////// return new NullJsonResult(); //////} //////public ActionResult UpdateSaleIncrement(AUIncrementRecord increment) //////{ ////// //TODO: AUTHORIZE ////// //if (!_permissionService.Authorize(StandardPermissionProvider.ManageCategories)) ////// // return AccessDeniedView(); ////// _incrementRepo.Update(increment); ////// return new NullJsonResult(); //////} //////public ActionResult ManageConsignors() //////{ ////// //%%%%%%%%%%%%%%%%%%% ////// //var listModel = new AUConsignorList ////// //{ ////// // //UsernamesEnabled = _customerSettings.UsernamesEnabled, ////// // //DateOfBirthEnabled = _customerSettings.DateOfBirthEnabled, ////// // //CompanyEnabled = _customerSettings.CompanyEnabled, ////// // //PhoneEnabled = _customerSettings.PhoneEnabled, ////// // //ZipPostalCodeEnabled = _customerSettings.ZipPostalCodeEnabled, ////// // //AvailableCustomerRoles = _customerService.GetAllCustomerRoles(true).Select(cr => cr.ToModel()).ToList(), ////// // //SearchCustomerRoleIds = defaultRoleIds, ////// //}; ////// //return View(listModel); ////// //return View(); ////// return View("~/Views/AUConsignor/ManageConsignors.cshtml"); //not hit first time?? //////} //public ActionResult CustomerList(DataSourceRequest command, CustomerListModel model, // [ModelBinder(typeof(CommaSeparatedModelBinder))] int[] searchCustomerRoleIds) //////[HttpPost] ////////************************************************************************************************************************************* //////// you had to pass in AUConsignorList model and populate it with the additionaldata function //////// in the cshtml to get the entered search data. ToTest: do you need DataSourceRequest?? Note, when just doing a total list, //////// you didn;t need to pass in anything //////public ActionResult ListConsignors(DataSourceRequest command, AUConsignorList model) //////{ ////// //********************************Original*******See Consignments for M-M ********************************************************* ////// //var consignors = _consignorRepo.Table.ToList(); ////// //var gridModel = new DataSourceResult ////// //{ ////// // Data = consignors.Select(x => new ////// // { ////// // AUConsignorID = x.AUConsignorID, ////// // FirstName = x.FirstName, ////// // MiddleName = x.MiddleName, ////// // LastName = x.LastName, ////// // CreateDate = x.CreateDate, ////// // BuyerFee = x.BuyerFee, ////// // SellerFee = x.SellerFee, ////// // }), ////// // Total = consignors.Count() ////// //}; ////// //*****************************Original******************************************************************* ////// int consignorid = 0; ////// string email = ""; ////// //string firstname = "Test"; ////// string lastname = ""; ////// string fn = model.searchFirstName; ////// var consignors = _consignorService.GetAllConsignors( ////// consignorId: consignorid, ////// WEmail: email, ////// firstName: model.searchFirstName, ////// lastName: lastname, ////// pageIndex: 0, ////// pageSize: 500); ////// //pageIndex: command.Page - 1, ////// //pageSize: command.PageSize); ////// var gridModel = new DataSourceResult ////// { ////// Data = consignors.Select(x => new ////// { ////// Id = x.Id, ////// AUConsignorID = x.AUConsignorID, ////// CustomerID = x.CustomerID, ////// FirstName = x.FirstName, ////// MiddleName = x.MiddleName, ////// LastName = x.LastName ////// }), ////// Total = consignors.TotalCount ////// }; ////// return Json(gridModel); //////} //////public ActionResult ManageSales() //////{ ////// //return View(); ////// return View("~/Views/AUConsignor/ManageSales.cshtml"); //not hit first time?? //////} //////public ActionResult ListSales(DataSourceRequest command, AUSaleList model) //////{ ////// var sales = _consignorService.GetAllSales( ////// saleId: model.searchAUSaleID, ////// saleNbr: model.searchSaleNbr, ////// saleTitle: model.searchSaleTitle, ////// pageIndex: 0, ////// pageSize: 500); ////// //pageIndex: command.Page - 1, ////// //pageSize: command.PageSize); ////// var gridModel = new DataSourceResult ////// { ////// Data = sales.Select(x => new ////// { ////// AUSaleID = x.AUSaleID, ////// SaleStoreID = x.SaleStoreID, ////// AUSaleNbr = x.AUSaleNbr, ////// SaleTitle = x.SaleTitle, ////// SaleDesc = x.SaleDesc, ////// // SaleStartDateTime = x.SaleStartDateTime, ////// // SaleEndDateTime = x.SaleEndDateTime, ////// SaleStartDateTime = _dateTimeHelper.ConvertToUserTime(x.SaleStartDateTime, DateTimeKind.Local), ////// SaleEndDateTime = _dateTimeHelper.ConvertToUserTime(x.SaleEndDateTime, DateTimeKind.Local), ////// }), ////// Total = sales.TotalCount ////// }; ////// return Json(gridModel); //////} //////public ActionResult ListUnassignedConsignors(DataSourceRequest command, AUCustomerList model) //////{ ////// int roleId = _consignorService.GetIdForRole("Consignors"); ////// int[] roleIds = new int[1]; ////// //Note: roleId may be 0 if Role was not found ////// roleIds[0] = roleId; ////// var vendors = _consignorService.GetUnassignedConsignorCustomers( ////// vendorId: model.SearchVendorId, ////// customerRoleIds: roleIds, ////// email: model.SearchEmail, ////// username: model.SearchUsername, ////// firstName: model.SearchFirstName, ////// lastName: model.SearchLastName, ////// company: model.SearchCompany, ////// phone: model.SearchPhone, ////// zipPostalCode: model.SearchZipPostalCode, ////// pageIndex: 0, ////// pageSize: 500); ////// //pageIndex: command.Page - 1, ////// //pageSize: command.PageSize); ////// //TODO: Add address, phone info to this result set (use nav property = select home address) ////// var gridModel = new DataSourceResult ////// { ////// Data = vendors.Select(x => new ////// { ////// Id = x.Id, ////// VendorId = x.VendorId, ////// CustomerGuid = x.CustomerGuid, ////// Firstname = (x.Addresses.Count() != 0) ? x.Addresses.First().FirstName : "No Address", ////// Lastname = (x.Addresses.Count() != 0) ? x.Addresses.First().LastName : "No Address", ////// Address1 = (x.Addresses.Count() != 0) ? x.Addresses.First().Address1 : "No Address", ////// Address2 = (x.Addresses.Count() != 0) ? x.Addresses.First().Address2 : "No Address", ////// City = (x.Addresses.Count() != 0) ? x.Addresses.First().City : "No Address", ////// ZipPostalCode = (x.Addresses.Count() != 0) ? x.Addresses.First().ZipPostalCode : "No Address", ////// Username = x.Username, ////// Company = (x.Addresses.Count() != 0) ? x.Addresses.First().Company : "No Address", ////// Phone = (x.Addresses.Count() != 0) ? x.Addresses.First().PhoneNumber : "No Address", ////// Email = x.Email, ////// AdminComment = x.AdminComment, ////// HasShoppingCartItems = x.HasShoppingCartItems, ////// Active = x.Active, ////// CreatedOnUtc = x.CreatedOnUtc, ////// LastLoginDateUtc = x.LastLoginDateUtc, ////// LastActivityDateUtc = x.LastActivityDateUtc ////// }), ////// Total = vendors.TotalCount ////// }; ////// return Json(gridModel); //////} //TODO: what is this DECORATION from Web CatalogController.cs // [NopHttpsRequirement(SslRequirement.No)] //WARNING!!! This is for the search page breadcrumb only! //TODO: what is this DECORATION from Web CatalogController.cs // [NopHttpsRequirement(SslRequirement.No)] public ActionResult Category(int categoryId, int? saleId, string children, string allChildren, CatalogPagingFilteringModel command) { int inSaleId = saleId.GetValueOrDefault(); //NJM: make it 0 if it's null. will be null coming off the Catalog breadcrumb bool manageCategoriesBySale = true; //TODO: placeholder to determine type of store and if manage categories by sale var category = new Category(); if (categoryId != 0) //NJM: may pass as zero if trying to present category page for sale only- off sale navigator or sale breadcrumb { category = _categoryService.GetCategoryById(categoryId); if (category == null || category.Deleted) return InvokeHttp404(); //Check whether the current user has a "Manage catalog" permission //It allows him to preview a category before publishing if (!category.Published && !_permissionService.Authorize(StandardPermissionProvider.ManageCategories)) return InvokeHttp404(); //ACL (access control list) if (!_aclService.Authorize(category)) return InvokeHttp404(); //Store mapping if (!_storeMappingService.Authorize(category)) return InvokeHttp404(); } else { //NJM: TODO Stuff page info for now until you add to AUSale (like Category) category.AllowCustomersToSelectPageSize = true; category.PageSizeOptions = "6,3,9"; category.PageSize = 6; } //TODO: come back to this to save the last page to continue shopping ////////'Continue shopping' URL //////_genericAttributeService.SaveAttribute(_workContext.CurrentCustomer, ////// SystemCustomerAttributeNames.LastContinueShoppingPage, ////// _webHelper.GetThisPageUrl(false), ////// _storeContext.CurrentStore.Id); var model = category.ToAUModel(); //NJM: this maps Category to AUCategory but does not populate nested classes if (inSaleId != 0) //NJM: coming off sale navigator or breadcrumb, so get the sale title { var sale = _saleRepo.GetById(inSaleId); if (sale == null) { throw new NopException("SaleId not found for category " + saleId); } model.SaleId = inSaleId; //this is needed to allow hyperlink to specify sale constraint model.SaleTitle = sale.SaleTitle; //this is needed for the breadcrumb } //sorting PrepareSortingOptions(model.PagingFilteringContext, command); //view mode PrepareViewModes(model.PagingFilteringContext, command); //page size PreparePageSizeOptions(model.PagingFilteringContext, command, category.AllowCustomersToSelectPageSize, category.PageSizeOptions, category.PageSize); //price ranges //TODO: insert *estimate* in here for filtering? model.PagingFilteringContext.PriceRangeFilter.LoadPriceRangeFilters(category.PriceRanges, _webHelper, _priceFormatter); var selectedPriceRange = model.PagingFilteringContext.PriceRangeFilter.GetSelectedPriceRange(_webHelper, category.PriceRanges); decimal? minPriceConverted = null; decimal? maxPriceConverted = null; if (selectedPriceRange != null) { if (selectedPriceRange.From.HasValue) minPriceConverted = _currencyService.ConvertToPrimaryStoreCurrency(selectedPriceRange.From.Value, _workContext.WorkingCurrency); if (selectedPriceRange.To.HasValue) maxPriceConverted = _currencyService.ConvertToPrimaryStoreCurrency(selectedPriceRange.To.Value, _workContext.WorkingCurrency); } //******************************************************************************************************************* //* The category breadcrumb s/b ok because it looks at the hierarchy above the current node, which is stable //* regardless if a lot is associated //************************************************************************************************************** //category breadcrumb if (_catalogSettings.CategoryBreadcrumbEnabled) { model.DisplayCategoryBreadcrumb = true; string breadcrumbCacheKey = string.Format(ModelCacheEventConsumer.CATEGORY_BREADCRUMB_KEY, categoryId, string.Join(",", _workContext.CurrentCustomer.GetCustomerRoleIds()), _storeContext.CurrentStore.Id, _workContext.WorkingLanguage.Id); //%%%get the breadcrumb here model.CategoryBreadcrumb = _cacheManager.Get(breadcrumbCacheKey, () => category .GetCategoryBreadCrumb(_categoryService, _aclService, _storeMappingService) .Select(catBr => new AUCategoryModel { Id = catBr.Id, SaleId = inSaleId, Name = catBr.GetLocalized(x => x.Name), SeName = catBr.GetSeName() }) .ToList() ); } //******************************************************************************************************************* //* Subcategories need modification because you only want to show subs that have a lot associated for this sale if sale provided //* this will affect what shows in the main panel when you click the parent node, and also affects child categores passed in the url to //* this action from the breadcrumb and navigator //************************************************************************************************************** //TODO deteermine if store wants to manage categories by sale. if so, use special stored procedure, otherwise use standard nop //logic to show raw category tree. use temporary variable for interim to control flow if (manageCategoriesBySale) { string subCategoriesCacheKey = string.Format(AUModelCacheEventConsumer.SALE_CATEGORY_SUBCATEGORIES_KEY, inSaleId, categoryId, string.Join(",", _workContext.CurrentCustomer.GetCustomerRoleIds()), _storeContext.CurrentStore.Id, _workContext.WorkingLanguage.Id, _webHelper.IsCurrentConnectionSecured()); model.SubCategories = _cacheManager.Get(subCategoriesCacheKey, () => _ausaleService.GetSaleCategoriesByParentCategoryId(inSaleId, categoryId) .Select(x => { var subCatModel = new AUCategoryModel.SubCategoryModel { Id = x.Id, Name = x.GetLocalized(y => y.Name), SeName = x.GetSeName(), }; //prepare picture model int pictureSize = _mediaSettings.CategoryThumbPictureSize; var categoryPictureCacheKey = string.Format(ModelCacheEventConsumer.CATEGORY_PICTURE_MODEL_KEY, x.Id, pictureSize, true, _workContext.WorkingLanguage.Id, _webHelper.IsCurrentConnectionSecured(), _storeContext.CurrentStore.Id); subCatModel.PictureModel = _cacheManager.Get(categoryPictureCacheKey, () => { var picture = _pictureService.GetPictureById(x.PictureId); var pictureModel = new PictureModel { FullSizeImageUrl = _pictureService.GetPictureUrl(picture), ImageUrl = _pictureService.GetPictureUrl(picture, pictureSize), Title = string.Format(_localizationService.GetResource("Media.Category.ImageLinkTitleFormat"), subCatModel.Name), AlternateText = string.Format(_localizationService.GetResource("Media.Category.ImageAlternateTextFormat"), subCatModel.Name) }; return pictureModel; }); return subCatModel; }) .ToList() ); } else //sale id is not present so get the raw hierarchy based on the category id passed in - original nop logic { string subCategoriesCacheKey = string.Format(ModelCacheEventConsumer.CATEGORY_SUBCATEGORIES_KEY, categoryId, string.Join(",", _workContext.CurrentCustomer.GetCustomerRoleIds()), _storeContext.CurrentStore.Id, _workContext.WorkingLanguage.Id, _webHelper.IsCurrentConnectionSecured()); model.SubCategories = _cacheManager.Get(subCategoriesCacheKey, () => _categoryService.GetAllCategoriesByParentCategoryId(categoryId) .Select(x => { var subCatModel = new CategoryModel.SubCategoryModel { Id = x.Id, Name = x.GetLocalized(y => y.Name), SeName = x.GetSeName(), }; //prepare picture model //TODO: refactor to define only once (see above) int pictureSize = _mediaSettings.CategoryThumbPictureSize; var categoryPictureCacheKey = string.Format(ModelCacheEventConsumer.CATEGORY_PICTURE_MODEL_KEY, x.Id, pictureSize, true, _workContext.WorkingLanguage.Id, _webHelper.IsCurrentConnectionSecured(), _storeContext.CurrentStore.Id); subCatModel.PictureModel = _cacheManager.Get(categoryPictureCacheKey, () => { var picture = _pictureService.GetPictureById(x.PictureId); var pictureModel = new PictureModel { FullSizeImageUrl = _pictureService.GetPictureUrl(picture), ImageUrl = _pictureService.GetPictureUrl(picture, pictureSize), Title = string.Format(_localizationService.GetResource("Media.Category.ImageLinkTitleFormat"), subCatModel.Name), AlternateText = string.Format(_localizationService.GetResource("Media.Category.ImageAlternateTextFormat"), subCatModel.Name) }; return pictureModel; }); return subCatModel.ToAUSubCatModel(); //NJM converting CategoryModel.SubCategoryModel to AUCategoryModel.SubCategoryModel }) .ToList() ); } //featured products //TODO - maybe want only featured products for the sales?? if (categoryId != 0) //may pass as zero if trying to present category page for sale only. For now don't show sale level featured products { if (!_catalogSettings.IgnoreFeaturedProducts) { //We cache a value indicating whether we have featured products IPagedList<Product> featuredProducts = null; string cacheKey = string.Format(ModelCacheEventConsumer.CATEGORY_HAS_FEATURED_PRODUCTS_KEY, categoryId, string.Join(",", _workContext.CurrentCustomer.GetCustomerRoleIds()), _storeContext.CurrentStore.Id); var hasFeaturedProductsCache = _cacheManager.Get<bool?>(cacheKey); if (!hasFeaturedProductsCache.HasValue) { //no value in the cache yet //let's load products and cache the result (true/false) featuredProducts = _productService.SearchProducts( categoryIds: new List<int> { category.Id }, storeId: _storeContext.CurrentStore.Id, visibleIndividuallyOnly: true, featuredProducts: true); hasFeaturedProductsCache = featuredProducts.TotalCount > 0; _cacheManager.Set(cacheKey, hasFeaturedProductsCache, 60); } if (hasFeaturedProductsCache.Value && featuredProducts == null) { //cache indicates that the category has featured products //let's load them featuredProducts = _productService.SearchProducts( categoryIds: new List<int> { category.Id }, storeId: _storeContext.CurrentStore.Id, visibleIndividuallyOnly: true, featuredProducts: true); } if (featuredProducts != null) { model.FeaturedProducts = PrepareProductOverviewModels(featuredProducts).ToList(); } } } //Gets ALL (raw) subcategories t the category passed in. If sale is provided, stored proc will only show lots in this sale in these categories var categoryIds = new List<int>(); categoryIds.Add(category.Id); if (_catalogSettings.ShowProductsFromSubcategories) { //original--> categoryIds.AddRange(GetChildCategoryIds(category.Id)); } IList<int> alreadyFilteredSpecOptionIds = model.PagingFilteringContext.SpecificationFilter.GetAlreadyFilteredSpecOptionIds(_webHelper); IList<int> filterableSpecificationAttributeOptionIds; var lots = _consignorService.GetAllLots2( out filterableSpecificationAttributeOptionIds, true, categoryIds: categoryIds, saleId: inSaleId, storeId: _storeContext.CurrentStore.Id, visibleIndividuallyOnly: true, featuredProducts: _catalogSettings.IncludeFeaturedProductsInNormalLists ? null : (bool?)false, priceMin: minPriceConverted, priceMax: maxPriceConverted, filteredSpecs: alreadyFilteredSpecOptionIds, //orderBy: (ProductSortingEnum)command.OrderBy ---> not working? //TODO: fix ordering (enum issue?) //warehouseId: model.SearchWarehouseId, //productType: model.SearchProductTypeId > 0 ? (ProductType?)model.SearchProductTypeId : null, //keywords: model.SearchProductName, //pageIndex: command.PageNumber - 1, //pageSize: command.PageSize, showHidden: false, overridePublished: true ).Select(x => x.ToProduct()).ToList(); //NJM: Important! Notice embedded "ToProduct mapping to get from AUCombLotProc to Product //this is where you need to change to insert the bidding info int totalRecords = lots.Count; int pageIndex = command.PageNumber - 1; int pageSize = command.PageSize; //int totalRecords = (pTotalRecords.Value != DBNull.Value) ? Convert.ToInt32(pTotalRecords.Value) : 0; //var products = new PagedList<Product>(lots, pageIndex, pageSize, totalRecords); //NJM: need to cast lots List to IPagedList so can be used in model.PagingFilteringContext.LoadPagedList(products); var products = new PagedList<Product>(lots, pageIndex, pageSize, totalRecords); //var products = _productService.SearchProducts(out filterableSpecificationAttributeOptionIds, true, // categoryIds: categoryIds, // storeId: _storeContext.CurrentStore.Id, // visibleIndividuallyOnly: true, // featuredProducts: _catalogSettings.IncludeFeaturedProductsInNormalLists ? null : (bool?)false, // priceMin: minPriceConverted, // priceMax: maxPriceConverted, // filteredSpecs: alreadyFilteredSpecOptionIds, // orderBy: (ProductSortingEnum)command.OrderBy, // pageIndex: command.PageNumber - 1, // pageSize: command.PageSize); //&&&&&&&&&&&&&this function should return AU model.Products = PrepareProductOverviewModels(products).ToList(); //IPagedList<Product> products model.PagingFilteringContext.LoadPagedList(products); //specs model.PagingFilteringContext.SpecificationFilter.PrepareSpecsFilters(alreadyFilteredSpecOptionIds, filterableSpecificationAttributeOptionIds, _specificationAttributeService, _webHelper, _workContext); //template var templateCacheKey = string.Format(ModelCacheEventConsumer.CATEGORY_TEMPLATE_MODEL_KEY, category.CategoryTemplateId); var templateViewPath = _cacheManager.Get(templateCacheKey, () => { var template = _categoryTemplateService.GetCategoryTemplateById(category.CategoryTemplateId); if (template == null) template = _categoryTemplateService.GetAllCategoryTemplates().FirstOrDefault(); if (template == null) throw new Exception("No default template could be loaded"); return template.ViewPath; }); //activity log _customerActivityService.InsertActivity("PublicStore.ViewCategory", _localizationService.GetResource("ActivityLog.PublicStore.ViewCategory"), category.Name); return View(templateViewPath, model); }
/// <summary> /// Update HasDiscountsApplied property (used for performance optimization) /// </summary> /// <param name="category">Category</param> public virtual void UpdateHasDiscountsApplied(Category category) { if (category == null) throw new ArgumentNullException("category"); category.HasDiscountsApplied = category.AppliedDiscounts.Count > 0; UpdateCategory(category); }
/// <summary> /// Delete category /// </summary> /// <param name="category">Category</param> public virtual void DeleteCategory(Category category) { if (category == null) throw new ArgumentNullException("category"); //reset a "Parent category" property of all child subcategories var subcategories = GetAllCategoriesByParentCategoryId(category.Id, true); foreach (var subcategory in subcategories) { subcategory.ParentCategoryId = 0; UpdateCategory(subcategory); } var builder = Builders<Product>.Update; var updatefilter = builder.PullFilter(x => x.ProductCategories, y => y.CategoryId == category.Id); var result = _productRepository.Collection.UpdateManyAsync(new BsonDocument(), updatefilter).Result; _categoryRepository.Delete(category); _cacheManager.RemoveByPattern(PRODUCTS_PATTERN_KEY); _cacheManager.RemoveByPattern(CATEGORIES_PATTERN_KEY); }
private void PrepareStoresMappingModel(CategoryModel model, Category category, bool excludeProperties) { if (model == null) throw new ArgumentNullException("model"); model.AvailableStores = _storeService .GetAllStores() .Select(s => s.ToModel()) .ToList(); if (!excludeProperties) { if (category != null) { model.SelectedStoreIds = _storeMappingService.GetStoresIdsWithAccess(category); } else { model.SelectedStoreIds = new int[0]; } } }
protected void SaveStoreMappings(Category category, CategoryModel model) { var existingStoreMappings = _storeMappingService.GetStoreMappings(category); var allStores = _storeService.GetAllStores(); foreach (var store in allStores) { if (model.SelectedStoreIds != null && model.SelectedStoreIds.Contains(store.Id)) { //new role if (existingStoreMappings.Count(sm => sm.StoreId == store.Id) == 0) _storeMappingService.InsertStoreMapping(category, store.Id); } else { //removed role var storeMappingToDelete = existingStoreMappings.FirstOrDefault(sm => sm.StoreId == store.Id); if (storeMappingToDelete != null) _storeMappingService.DeleteStoreMapping(storeMappingToDelete); } } }
protected virtual void PrepareStoresMappingModel(CategoryModel model, Category category, bool excludeProperties) { if (model == null) throw new ArgumentNullException("model"); model.AvailableStores = _storeService .GetAllStores() .Select(s => s.ToModel()) .ToList(); if (!excludeProperties) { if (category != null) { model.SelectedStoreIds = category.Stores.ToArray(); } } }
protected virtual void InstallCategories() { //pictures var pictureService = EngineContext.Current.Resolve<IPictureService>(); var sampleImagesPath = _webHelper.MapPath("~/content/samples/"); var categoryTemplateInGridAndLines = _categoryTemplateRepository .Table.FirstOrDefault(pt => pt.Name == "Products in Grid or Lines"); if (categoryTemplateInGridAndLines == null) throw new Exception("Category template cannot be loaded"); //categories var allCategories = new List<Category>(); var categoryComputers = new Category { Id = 1, Name = "Computers", CategoryTemplateId = categoryTemplateInGridAndLines.Id, PageSize = 6, AllowCustomersToSelectPageSize = true, PageSizeOptions = "6, 3, 9", PictureId = pictureService.InsertPicture(File.ReadAllBytes(sampleImagesPath + "category_computers.jpeg"), "image/jpeg", pictureService.GetPictureSeName("Computers")).Id, IncludeInTopMenu = true, Published = true, DisplayOrder = 1, CreatedOnUtc = DateTime.UtcNow, UpdatedOnUtc = DateTime.UtcNow }; allCategories.Add(categoryComputers); var categoryDesktops = new Category { Id = 2, Name = "Desktops", CategoryTemplateId = categoryTemplateInGridAndLines.Id, PageSize = 6, AllowCustomersToSelectPageSize = true, PageSizeOptions = "6, 3, 9", ParentCategoryId = categoryComputers.Id, PictureId = pictureService.InsertPicture(File.ReadAllBytes(sampleImagesPath + "category_desktops.jpg"), "image/pjpeg", pictureService.GetPictureSeName("Desktops")).Id, PriceRanges = "-1000;1000-1200;1200-;", IncludeInTopMenu = true, Published = true, DisplayOrder = 1, CreatedOnUtc = DateTime.UtcNow, UpdatedOnUtc = DateTime.UtcNow }; allCategories.Add(categoryDesktops); var categoryNotebooks = new Category { Id = 3, Name = "Notebooks", CategoryTemplateId = categoryTemplateInGridAndLines.Id, PageSize = 6, AllowCustomersToSelectPageSize = true, PageSizeOptions = "6, 3, 9", ParentCategoryId = categoryComputers.Id, PictureId = pictureService.InsertPicture(File.ReadAllBytes(sampleImagesPath + "category_notebooks.jpg"), "image/pjpeg", pictureService.GetPictureSeName("Notebooks")).Id, IncludeInTopMenu = true, Published = true, DisplayOrder = 2, CreatedOnUtc = DateTime.UtcNow, UpdatedOnUtc = DateTime.UtcNow }; allCategories.Add(categoryNotebooks); var categorySoftware = new Category { Id = 4, Name = "Software", CategoryTemplateId = categoryTemplateInGridAndLines.Id, PageSize = 6, AllowCustomersToSelectPageSize = true, PageSizeOptions = "6, 3, 9", ParentCategoryId = categoryComputers.Id, PictureId = pictureService.InsertPicture(File.ReadAllBytes(sampleImagesPath + "category_software.jpg"), "image/pjpeg", pictureService.GetPictureSeName("Software")).Id, IncludeInTopMenu = true, Published = true, DisplayOrder = 3, CreatedOnUtc = DateTime.UtcNow, UpdatedOnUtc = DateTime.UtcNow }; allCategories.Add(categorySoftware); var categoryElectronics = new Category { Id = 5, Name = "Electronics", CategoryTemplateId = categoryTemplateInGridAndLines.Id, PageSize = 6, AllowCustomersToSelectPageSize = true, PageSizeOptions = "6, 3, 9", PictureId = pictureService.InsertPicture(File.ReadAllBytes(sampleImagesPath + "category_electronics.jpeg"), "image/jpeg", pictureService.GetPictureSeName("Electronics")).Id, IncludeInTopMenu = true, Published = true, ShowOnHomePage = true, DisplayOrder = 2, CreatedOnUtc = DateTime.UtcNow, UpdatedOnUtc = DateTime.UtcNow }; allCategories.Add(categoryElectronics); var categoryCameraPhoto = new Category { Id = 6, Name = "Camera & photo", CategoryTemplateId = categoryTemplateInGridAndLines.Id, PageSize = 6, AllowCustomersToSelectPageSize = true, PageSizeOptions = "6, 3, 9", ParentCategoryId = categoryElectronics.Id, PictureId = pictureService.InsertPicture(File.ReadAllBytes(sampleImagesPath + "category_camera_photo.jpeg"), "image/jpeg", pictureService.GetPictureSeName("Camera, photo")).Id, PriceRanges = "-500;500-;", IncludeInTopMenu = true, Published = true, DisplayOrder = 1, CreatedOnUtc = DateTime.UtcNow, UpdatedOnUtc = DateTime.UtcNow }; allCategories.Add(categoryCameraPhoto); var categoryCellPhones = new Category { Id = 7, Name = "Cell phones", CategoryTemplateId = categoryTemplateInGridAndLines.Id, PageSize = 6, AllowCustomersToSelectPageSize = true, PageSizeOptions = "6, 3, 9", ParentCategoryId = categoryElectronics.Id, PictureId = pictureService.InsertPicture(File.ReadAllBytes(sampleImagesPath + "category_cell_phones.jpeg"), "image/jpeg", pictureService.GetPictureSeName("Cell phones")).Id, IncludeInTopMenu = true, Published = true, DisplayOrder = 2, CreatedOnUtc = DateTime.UtcNow, UpdatedOnUtc = DateTime.UtcNow }; allCategories.Add(categoryCellPhones); var categoryOthers = new Category { Id = 8, Name = "Others", CategoryTemplateId = categoryTemplateInGridAndLines.Id, PageSize = 6, AllowCustomersToSelectPageSize = true, PageSizeOptions = "6, 3, 9", ParentCategoryId = categoryElectronics.Id, PictureId = pictureService.InsertPicture(File.ReadAllBytes(sampleImagesPath + "category_accessories.jpg"), "image/pjpeg", pictureService.GetPictureSeName("Accessories")).Id, IncludeInTopMenu = true, PriceRanges = "-100;100-;", Published = true, DisplayOrder = 3, CreatedOnUtc = DateTime.UtcNow, UpdatedOnUtc = DateTime.UtcNow }; allCategories.Add(categoryOthers); var categoryApparel = new Category { Id = 9, Name = "Apparel", CategoryTemplateId = categoryTemplateInGridAndLines.Id, PageSize = 6, AllowCustomersToSelectPageSize = true, PageSizeOptions = "6, 3, 9", PictureId = pictureService.InsertPicture(File.ReadAllBytes(sampleImagesPath + "category_apparel.jpeg"), "image/jpeg", pictureService.GetPictureSeName("Apparel")).Id, IncludeInTopMenu = true, Published = true, ShowOnHomePage = true, DisplayOrder = 3, CreatedOnUtc = DateTime.UtcNow, UpdatedOnUtc = DateTime.UtcNow }; allCategories.Add(categoryApparel); var categoryShoes = new Category { Id = 10, Name = "Shoes", CategoryTemplateId = categoryTemplateInGridAndLines.Id, PageSize = 6, AllowCustomersToSelectPageSize = true, PageSizeOptions = "6, 3, 9", ParentCategoryId = categoryApparel.Id, PictureId = pictureService.InsertPicture(File.ReadAllBytes(sampleImagesPath + "category_shoes.jpeg"), "image/jpeg", pictureService.GetPictureSeName("Shoes")).Id, PriceRanges = "-500;500-;", IncludeInTopMenu = true, Published = true, DisplayOrder = 1, CreatedOnUtc = DateTime.UtcNow, UpdatedOnUtc = DateTime.UtcNow }; allCategories.Add(categoryShoes); var categoryClothing = new Category { Id = 11, Name = "Clothing", CategoryTemplateId = categoryTemplateInGridAndLines.Id, PageSize = 6, AllowCustomersToSelectPageSize = true, PageSizeOptions = "6, 3, 9", ParentCategoryId = categoryApparel.Id, PictureId = pictureService.InsertPicture(File.ReadAllBytes(sampleImagesPath + "category_clothing.jpeg"), "image/jpeg", pictureService.GetPictureSeName("Clothing")).Id, IncludeInTopMenu = true, Published = true, DisplayOrder = 2, CreatedOnUtc = DateTime.UtcNow, UpdatedOnUtc = DateTime.UtcNow }; allCategories.Add(categoryClothing); var categoryAccessories = new Category { Id = 12, Name = "Accessories", CategoryTemplateId = categoryTemplateInGridAndLines.Id, PageSize = 6, AllowCustomersToSelectPageSize = true, PageSizeOptions = "6, 3, 9", ParentCategoryId = categoryApparel.Id, PictureId = pictureService.InsertPicture(File.ReadAllBytes(sampleImagesPath + "category_apparel_accessories.jpg"), "image/pjpeg", pictureService.GetPictureSeName("Apparel Accessories")).Id, IncludeInTopMenu = true, PriceRanges = "-100;100-;", Published = true, DisplayOrder = 3, CreatedOnUtc = DateTime.UtcNow, UpdatedOnUtc = DateTime.UtcNow }; allCategories.Add(categoryAccessories); var categoryDigitalDownloads = new Category { Id = 13, Name = "Digital downloads", CategoryTemplateId = categoryTemplateInGridAndLines.Id, PageSize = 6, AllowCustomersToSelectPageSize = true, PageSizeOptions = "6, 3, 9", PictureId = pictureService.InsertPicture(File.ReadAllBytes(sampleImagesPath + "category_digital_downloads.jpeg"), "image/jpeg", pictureService.GetPictureSeName("Digital downloads")).Id, IncludeInTopMenu = true, Published = true, ShowOnHomePage = true, DisplayOrder = 4, CreatedOnUtc = DateTime.UtcNow, UpdatedOnUtc = DateTime.UtcNow }; allCategories.Add(categoryDigitalDownloads); var categoryBooks = new Category { Id = 14, Name = "Books", CategoryTemplateId = categoryTemplateInGridAndLines.Id, MetaKeywords = "Books, Dictionary, Textbooks", MetaDescription = "Books category description", PageSize = 6, AllowCustomersToSelectPageSize = true, PageSizeOptions = "6, 3, 9", PictureId = pictureService.InsertPicture(File.ReadAllBytes(sampleImagesPath + "category_book.jpeg"), "image/jpeg", pictureService.GetPictureSeName("Book")).Id, PriceRanges = "-25;25-50;50-;", IncludeInTopMenu = true, Published = true, DisplayOrder = 5, CreatedOnUtc = DateTime.UtcNow, UpdatedOnUtc = DateTime.UtcNow }; allCategories.Add(categoryBooks); var categoryJewelry = new Category { Id = 15, Name = "Jewelry", CategoryTemplateId = categoryTemplateInGridAndLines.Id, PageSize = 6, AllowCustomersToSelectPageSize = true, PageSizeOptions = "6, 3, 9", PictureId = pictureService.InsertPicture(File.ReadAllBytes(sampleImagesPath + "category_jewelry.jpeg"), "image/jpeg", pictureService.GetPictureSeName("Jewelry")).Id, PriceRanges = "0-500;500-700;700-3000;", IncludeInTopMenu = true, Published = true, DisplayOrder = 6, CreatedOnUtc = DateTime.UtcNow, UpdatedOnUtc = DateTime.UtcNow }; allCategories.Add(categoryJewelry); var categoryGiftCards = new Category { Id = 16, Name = "Gift Cards", CategoryTemplateId = categoryTemplateInGridAndLines.Id, PageSize = 6, AllowCustomersToSelectPageSize = true, PageSizeOptions = "6, 3, 9", PictureId = pictureService.InsertPicture(File.ReadAllBytes(sampleImagesPath + "category_gift_cards.jpeg"), "image/jpeg", pictureService.GetPictureSeName("Gift Cards")).Id, IncludeInTopMenu = true, Published = true, DisplayOrder = 7, CreatedOnUtc = DateTime.UtcNow, UpdatedOnUtc = DateTime.UtcNow }; allCategories.Add(categoryGiftCards); _categoryRepository.Insert(allCategories); //search engine names foreach (var category in allCategories) { category.SeName = category.ValidateSeName("", category.Name, true); _urlRecordRepository.Insert(new UrlRecord { EntityId = category.Id, EntityName = "Category", LanguageId = 0, IsActive = true, Slug = category.SeName, }); _categoryRepository.Update(category); } }
protected virtual List<LocalizedProperty> UpdateLocales(Category category, CategoryModel model) { List<LocalizedProperty> localized = new List<LocalizedProperty>(); foreach (var local in model.Locales) { var seName = category.ValidateSeName(local.SeName, local.Name, false); _urlRecordService.SaveSlug(category, seName, local.LanguageId); if (!(String.IsNullOrEmpty(seName))) localized.Add(new LocalizedProperty() { LanguageId = local.LanguageId, LocaleKey = "SeName", LocaleValue = seName, _id = ObjectId.GenerateNewId().ToString(), Id = localized.Count > 0 ? localized.Max(x => x.Id) + 1 : 1, }); if (!(String.IsNullOrEmpty(local.Description))) localized.Add(new LocalizedProperty() { LanguageId = local.LanguageId, LocaleKey = "Description", LocaleValue = local.Description, _id = ObjectId.GenerateNewId().ToString(), Id = localized.Count > 0 ? localized.Max(x => x.Id) + 1 : 1, }); if (!(String.IsNullOrEmpty(local.MetaDescription))) localized.Add(new LocalizedProperty() { LanguageId = local.LanguageId, LocaleKey = "MetaDescription", LocaleValue = local.MetaDescription, _id = ObjectId.GenerateNewId().ToString(), Id = localized.Count > 0 ? localized.Max(x => x.Id) + 1 : 1, }); if (!(String.IsNullOrEmpty(local.MetaKeywords))) localized.Add(new LocalizedProperty() { LanguageId = local.LanguageId, LocaleKey = "MetaKeywords", LocaleValue = local.MetaKeywords, _id = ObjectId.GenerateNewId().ToString(), Id = localized.Count > 0 ? localized.Max(x => x.Id) + 1 : 1, }); if (!(String.IsNullOrEmpty(local.MetaTitle))) localized.Add(new LocalizedProperty() { LanguageId = local.LanguageId, LocaleKey = "MetaTitle", LocaleValue = local.MetaTitle, _id = ObjectId.GenerateNewId().ToString(), Id = localized.Count > 0 ? localized.Max(x => x.Id) + 1 : 1, }); if (!(String.IsNullOrEmpty(local.Name))) localized.Add(new LocalizedProperty() { LanguageId = local.LanguageId, LocaleKey = "Name", LocaleValue = local.Name, _id = ObjectId.GenerateNewId().ToString(), Id = localized.Count > 0 ? localized.Max(x => x.Id) + 1 : 1, }); } return localized; }
public static Category ToEntity(this CategoryModel model, Category destination) { return Mapper.Map(model, destination); }
protected virtual void PrepareStoresMappingModel(CategoryModel model, Category category, bool excludeProperties) { if (model == null) throw new ArgumentNullException("model"); if (!excludeProperties && category != null) model.SelectedStoreIds = _storeMappingService.GetStoresIdsWithAccess(category).ToList(); var allStores = _storeService.GetAllStores(); foreach (var store in allStores) { model.AvailableStores.Add(new SelectListItem { Text = store.Name, Value = store.Id.ToString(), Selected = model.SelectedStoreIds.Contains(store.Id) }); } }
/// <summary> /// Inserts category /// </summary> /// <param name="category">Category</param> public virtual void InsertCategory(Category category) { if (category == null) throw new ArgumentNullException("category"); _categoryRepository.Insert(category); //cache _cacheManager.RemoveByPattern(CATEGORIES_PATTERN_KEY); _cacheManager.RemoveByPattern(PRODUCTCATEGORIES_PATTERN_KEY); //event notification _eventPublisher.EntityInserted(category); }
protected void UpdatePictureSeoNames(Category category) { var picture = _pictureService.GetPictureById(category.PictureId); if (picture != null) _pictureService.SetSeoFilename(picture.Id, _pictureService.GetPictureSeName(category.Name)); }
protected IList<CategoryNavigationModel> GetChildCategoryNavigationModel(IList<Category> breadCrumb, int rootCategoryId, Category currentCategory, int level) { var result = new List<CategoryNavigationModel>(); foreach (var category in _categoryService.GetAllCategoriesByParentCategoryId(rootCategoryId)) { var model = new CategoryNavigationModel() { Id = category.Id, Name = category.GetLocalized(x => x.Name), SeName = category.GetSeName(), IsActive = currentCategory != null && currentCategory.Id == category.Id, NumberOfParentCategories = level }; if (_catalogSettings.ShowCategoryProductNumber) { model.DisplayNumberOfProducts = true; var categoryIds = new List<int>(); categoryIds.Add(category.Id); if (_catalogSettings.ShowCategoryProductNumberIncludingSubcategories) { //include subcategories categoryIds.AddRange(GetChildCategoryIds(category.Id)); } IList<int> filterableSpecificationAttributeOptionIds = null; model.NumberOfProducts = _productService.SearchProducts(categoryIds, 0, null, null, null, 0, string.Empty, false, 0, null, ProductSortingEnum.Position, 0, 1, false, out filterableSpecificationAttributeOptionIds).TotalCount; } result.Add(model); // Comento las siguientes dos líneas para mostrar tanto Categorías como Subcategorias //for (int i = 0; i <= breadCrumb.Count - 1; i++) // if (breadCrumb[i].Id == category.Id) result.AddRange(GetChildCategoryNavigationModel(breadCrumb, category.Id, currentCategory, level + 1)); } return result; }
protected void PrepareDiscountModel(CategoryModel model, Category category, bool excludeProperties) { if (model == null) throw new ArgumentNullException("model"); model.AvailableDiscounts = _discountService .GetAllDiscounts(DiscountType.AssignedToCategories, null, true) .Select(d => d.ToModel()) .ToList(); if (!excludeProperties && category != null) { model.SelectedDiscountIds = category.AppliedDiscounts.Select(d => d.Id).ToArray(); } }