public ActionResult List(GridCommand command) { var model = new GridModel <AffiliateModel>(); if (_permissionService.Authorize(StandardPermissionProvider.ManageAffiliates)) { var affiliates = _affiliateService.GetAllAffiliates(true); model.Data = affiliates.PagedForCommand(command).Select(x => { var m = new AffiliateModel(); PrepareAffiliateModel(m, x, false); return(m); }); model.Total = affiliates.Count; } else { model.Data = Enumerable.Empty <AffiliateModel>(); NotifyAccessDenied(); } return(new JsonResult { Data = model }); }
public ActionResult Create(AffiliateModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageAffiliates)) { return(AccessDeniedView()); } if (ModelState.IsValid) { var affiliate = new Affiliate(); affiliate.Active = model.Active; affiliate.AdminComment = model.AdminComment; affiliate.Address = model.Address.ToEntity(); affiliate.Address.CreatedOnUtc = DateTime.UtcNow; //some validation if (affiliate.Address.CountryId == 0) { affiliate.Address.CountryId = null; } if (affiliate.Address.StateProvinceId == 0) { affiliate.Address.StateProvinceId = null; } _affiliateService.InsertAffiliate(affiliate); SuccessNotification(_localizationService.GetResource("Admin.Affiliates.Added")); return(continueEditing ? RedirectToAction("Edit", new { id = affiliate.Id }) : RedirectToAction("List")); } //If we got this far, something failed, redisplay form PrepareAffiliateModel(model, null, true); return(View(model)); }
public virtual IActionResult List(DataSourceRequest command, AffiliateListModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageAffiliates)) { return(AccessDeniedKendoGridJson()); } var affiliates = _affiliateService.GetAllAffiliates(model.SearchFriendlyUrlName, model.SearchFirstName, model.SearchLastName, model.LoadOnlyWithOrders, model.OrdersCreatedFromUtc, model.OrdersCreatedToUtc, command.Page - 1, command.PageSize, true); var gridModel = new DataSourceResult { Data = affiliates.Select(x => { var m = new AffiliateModel(); PrepareAffiliateModel(m, x, false, false, false); return(m); }), Total = affiliates.TotalCount, }; return(Json(gridModel)); }
public async Task <IActionResult> Edit(AffiliateModel model, bool continueEditing) { var affiliate = await _affiliateService.GetAffiliateById(model.Id); if (affiliate == null || affiliate.Deleted) { //No affiliate found with the specified id return(RedirectToAction("List")); } if (ModelState.IsValid) { affiliate = await _affiliateViewModelService.UpdateAffiliateModel(model, affiliate); SuccessNotification(_localizationService.GetResource("Admin.Affiliates.Updated")); if (continueEditing) { //selected tab await SaveSelectedTabIndex(); return(RedirectToAction("Edit", new { id = affiliate.Id })); } return(RedirectToAction("List")); } //If we got this far, something failed, redisplay form await _affiliateViewModelService.PrepareAffiliateModel(model, affiliate, true); return(View(model)); }
public ActionResult Create() { var model = new AffiliateModel(); PrepareAffiliateModel(model, null, false); return(View(model)); }
public ActionResult Create(AffiliateModel model, bool continueEditing) { if (ModelState.IsValid) { var affiliate = new Affiliate(); affiliate.Active = model.Active; affiliate.Address = model.Address.ToEntity(); affiliate.Address.CreatedOnUtc = DateTime.UtcNow; //some validation if (affiliate.Address.CountryId == 0) { affiliate.Address.CountryId = null; } if (affiliate.Address.StateProvinceId == 0) { affiliate.Address.StateProvinceId = null; } _affiliateService.InsertAffiliate(affiliate); NotifySuccess(T("Admin.Affiliates.Added")); return(continueEditing ? RedirectToAction("Edit", new { id = affiliate.Id }) : RedirectToAction("List")); } //If we got this far, something failed, redisplay form PrepareAffiliateModel(model, null, true); return(View(model)); }
public virtual IActionResult Edit(AffiliateModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageAffiliates)) { return(AccessDeniedView()); } //try to get an affiliate with the specified id var affiliate = _affiliateService.GetAffiliateById(model.Id); if (affiliate == null || affiliate.Deleted) { return(RedirectToAction("List")); } if (ModelState.IsValid) { affiliate = model.ToEntity(affiliate); //validate friendly URL name var friendlyUrlName = affiliate.ValidateFriendlyUrlName(model.FriendlyUrlName); affiliate.FriendlyUrlName = friendlyUrlName; affiliate.Address = model.Address.ToEntity(affiliate.Address); //some validation if (affiliate.Address.CountryId == 0) { affiliate.Address.CountryId = null; } if (affiliate.Address.StateProvinceId == 0) { affiliate.Address.StateProvinceId = null; } _affiliateService.UpdateAffiliate(affiliate); //activity log _customerActivityService.InsertActivity("EditAffiliate", string.Format(_localizationService.GetResource("ActivityLog.EditAffiliate"), affiliate.Id), affiliate); SuccessNotification(_localizationService.GetResource("Admin.Affiliates.Updated")); if (!continueEditing) { return(RedirectToAction("List")); } //selected tab SaveSelectedTabName(); return(RedirectToAction("Edit", new { id = affiliate.Id })); } //prepare model model = _affiliateModelFactory.PrepareAffiliateModel(model, affiliate, true); //if we got this far, something failed, redisplay form return(View(model)); }
/// <summary> /// Prepare affiliate model /// </summary> /// <param name="model">Affiliate model</param> /// <param name="affiliate">Affiliate</param> /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param> /// <returns>Affiliate model</returns> public virtual async Task <AffiliateModel> PrepareAffiliateModelAsync(AffiliateModel model, Affiliate affiliate, bool excludeProperties = false) { //fill in model values from the entity if (affiliate != null) { model ??= affiliate.ToModel <AffiliateModel>(); model.Url = await _affiliateService.GenerateUrlAsync(affiliate); //prepare nested search models await PrepareAffiliatedOrderSearchModelAsync(model.AffiliatedOrderSearchModel, affiliate); PrepareAffiliatedCustomerSearchModel(model.AffiliatedCustomerSearchModel, affiliate); //prepare address model var address = await _addressService.GetAddressByIdAsync(affiliate.AddressId); model.Address = address.ToModel(model.Address); await _baseAdminModelFactory.PrepareAddressModelAsync(model.Address, address); //whether to fill in some of properties if (!excludeProperties) { model.AdminComment = affiliate.AdminComment; model.FriendlyUrlName = affiliate.FriendlyUrlName; model.Active = affiliate.Active; } } else { await _baseAdminModelFactory.PrepareAddressModelAsync(model.Address); } return(model); }
public async Task <IActionResult> Create() { var model = new AffiliateModel(); await _affiliateViewModelService.PrepareAffiliateModel(model, null, false); return(View(model)); }
/// <summary> /// Prepare affiliate model /// </summary> /// <param name="model">Affiliate model</param> /// <param name="affiliate">Affiliate</param> /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param> /// <returns>Affiliate model</returns> public virtual AffiliateModel PrepareAffiliateModel(AffiliateModel model, Affiliate affiliate, bool excludeProperties = false) { //fill in model values from the entity if (affiliate != null) { model = model ?? affiliate.ToModel <AffiliateModel>(); model.Url = affiliate.GenerateUrl(_webHelper); //prepare nested search models PrepareAffiliatedOrderSearchModel(model.AffiliatedOrderSearchModel, affiliate); PrepareAffiliatedCustomerSearchModel(model.AffiliatedCustomerSearchModel, affiliate); //whether to fill in some of properties if (!excludeProperties) { model.AdminComment = affiliate.AdminComment; model.FriendlyUrlName = affiliate.FriendlyUrlName; model.Active = affiliate.Active; model.Address = affiliate.Address.ToModel(model.Address); } } //prepare address model PrepareAddressModel(model.Address, affiliate?.Address); return(model); }
//create public IActionResult Create() { var model = new AffiliateModel(); _affiliateViewModelService.PrepareAffiliateModel(model, null, false); return(View(model)); }
public ActionResult Create(AffiliateModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageAffiliates)) { return(AccessDeniedView()); } if (ModelState.IsValid) { var affiliate = new Affiliate(); affiliate.Active = model.Active; affiliate.AdminComment = model.AdminComment; //validate friendly URL name var friendlyUrlName = affiliate.ValidateFriendlyUrlName(model.FriendlyUrlName); affiliate.FriendlyUrlName = friendlyUrlName; affiliate.Address = model.Address.ToEntity(); affiliate.Address.Id = 1; affiliate.Address._id = ObjectId.GenerateNewId().ToString(); affiliate.Address.CreatedOnUtc = DateTime.UtcNow; //some validation _affiliateService.InsertAffiliate(affiliate); SuccessNotification(_localizationService.GetResource("Admin.Affiliates.Added")); return(continueEditing ? RedirectToAction("Edit", new { id = affiliate.Id }) : RedirectToAction("List")); } //If we got this far, something failed, redisplay form PrepareAffiliateModel(model, null, true); return(View(model)); }
public ActionResult Edit(AffiliateModel model, bool continueEditing) { var affiliate = _affiliateService.GetAffiliateById(model.Id); if (affiliate == null || affiliate.Deleted) { //No affiliate found with the specified id return(RedirectToAction("List")); } if (ModelState.IsValid) { affiliate.Active = model.Active; affiliate.Address = model.Address.ToEntity(affiliate.Address); //some validation if (affiliate.Address.CountryId == 0) { affiliate.Address.CountryId = null; } if (affiliate.Address.StateProvinceId == 0) { affiliate.Address.StateProvinceId = null; } _affiliateService.UpdateAffiliate(affiliate); NotifySuccess(T("Admin.Affiliates.Updated")); return(continueEditing ? RedirectToAction("Edit", affiliate.Id) : RedirectToAction("List")); } //If we got this far, something failed, redisplay form PrepareAffiliateModel(model, affiliate, true); return(View(model)); }
//create public ActionResult Create() { if (!_permissionService.Authorize(StandardPermissionProvider.ManageAffiliates)) { return(AccessDeniedView()); } var model = new AffiliateModel(); PrepareAffiliateModel(model, null, false); return(View(model)); }
public virtual Affiliate UpdateAffiliateModel(AffiliateModel model, Affiliate affiliate) { affiliate.Active = model.Active; affiliate.AdminComment = model.AdminComment; //validate friendly URL name var friendlyUrlName = affiliate.ValidateFriendlyUrlName(model.FriendlyUrlName); affiliate.FriendlyUrlName = friendlyUrlName; affiliate.Address = model.Address.ToEntity(affiliate.Address); _affiliateService.UpdateAffiliate(affiliate); return(affiliate); }
public IActionResult Create(AffiliateModel model, bool continueEditing) { if (ModelState.IsValid) { var affiliate = _affiliateViewModelService.InsertAffiliateModel(model); SuccessNotification(_localizationService.GetResource("Admin.Affiliates.Added")); return(continueEditing ? RedirectToAction("Edit", new { id = affiliate.Id }) : RedirectToAction("List")); } //If we got this far, something failed, redisplay form _affiliateViewModelService.PrepareAffiliateModel(model, null, true); return(View(model)); }
public virtual async Task <Affiliate> UpdateAffiliateModel(AffiliateModel model, Affiliate affiliate) { affiliate.Active = model.Active; affiliate.AdminComment = model.AdminComment; //validate friendly URL name var friendlyUrlName = await affiliate.ValidateFriendlyUrlName(_affiliateService, _seoSettings, model.FriendlyUrlName); affiliate.FriendlyUrlName = friendlyUrlName; affiliate.Address = model.Address.ToEntity(affiliate.Address); await _affiliateService.UpdateAffiliate(affiliate); return(affiliate); }
private void PrepareAffiliateModel(AffiliateModel model, Affiliate affiliate, bool excludeProperties) { if (model == null) { throw new ArgumentNullException("model"); } if (affiliate != null) { model.Id = affiliate.Id; model.Url = _webHelper.ModifyQueryString(_webHelper.GetStoreLocation(false), "affiliateid=" + affiliate.Id, null); if (!excludeProperties) { model.Active = affiliate.Active; model.Address = affiliate.Address.ToModel(); } } //address model.Address.AvailableCountries.Add(new SelectListItem() { Text = _localizationService.GetResource("Admin.Address.SelectCountry"), Value = "0" }); foreach (var c in _countryService.GetAllCountries(true)) { model.Address.AvailableCountries.Add(new SelectListItem() { Text = c.Name, Value = c.Id.ToString(), Selected = (affiliate != null && c.Id == affiliate.Address.CountryId) }); } var states = model.Address.CountryId.HasValue ? _stateProvinceService.GetStateProvincesByCountryId(model.Address.CountryId.Value, true).ToList() : new List <StateProvince>(); if (states.Count > 0) { foreach (var s in states) { model.Address.AvailableStates.Add(new SelectListItem() { Text = s.Name, Value = s.Id.ToString(), Selected = (affiliate != null && s.Id == affiliate.Address.StateProvinceId) }); } } else { model.Address.AvailableStates.Add(new SelectListItem() { Text = _localizationService.GetResource("Admin.Address.OtherNonUS"), Value = "0" }); } }
public virtual async Task <IActionResult> Create(AffiliateModel model, bool continueEditing) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageAffiliates)) { return(AccessDeniedView()); } if (ModelState.IsValid) { var address = model.Address.ToEntity <Address>(); address.CreatedOnUtc = DateTime.UtcNow; //some validation if (address.CountryId == 0) { address.CountryId = null; } if (address.StateProvinceId == 0) { address.StateProvinceId = null; } await _addressService.InsertAddressAsync(address); var affiliate = model.ToEntity <Affiliate>(); //validate friendly URL name var friendlyUrlName = await _affiliateService.ValidateFriendlyUrlNameAsync(affiliate, model.FriendlyUrlName); affiliate.FriendlyUrlName = friendlyUrlName; affiliate.AddressId = address.Id; await _affiliateService.InsertAffiliateAsync(affiliate); //activity log await _customerActivityService.InsertActivityAsync("AddNewAffiliate", string.Format(await _localizationService.GetResourceAsync("ActivityLog.AddNewAffiliate"), affiliate.Id), affiliate); _notificationService.SuccessNotification(await _localizationService.GetResourceAsync("Admin.Affiliates.Added")); return(continueEditing ? RedirectToAction("Edit", new { id = affiliate.Id }) : RedirectToAction("List")); } //prepare model model = await _affiliateModelFactory.PrepareAffiliateModelAsync(model, null, true); //if we got this far, something failed, redisplay form return(View(model)); }
public virtual (IEnumerable <AffiliateModel> affiliateModels, int totalCount) PrepareAffiliateModelList(AffiliateListModel model, int pageIndex, int pageSize) { var affiliates = _affiliateService.GetAllAffiliates(model.SearchFriendlyUrlName, model.SearchFirstName, model.SearchLastName, model.LoadOnlyWithOrders, model.OrdersCreatedFromUtc, model.OrdersCreatedToUtc, pageIndex - 1, pageSize, true); return(affiliates.Select(x => { var m = new AffiliateModel(); PrepareAffiliateModel(m, x, false, false); return m; }), affiliates.TotalCount); }
public virtual IActionResult Create(AffiliateModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageAffiliates)) { return(AccessDeniedView()); } if (ModelState.IsValid) { var affiliate = new Affiliate { Active = model.Active, AdminComment = model.AdminComment }; //validate friendly URL name var friendlyUrlName = affiliate.ValidateFriendlyUrlName(model.FriendlyUrlName); affiliate.FriendlyUrlName = friendlyUrlName; affiliate.Address = model.Address.ToEntity(); affiliate.Address.CreatedOnUtc = DateTime.UtcNow; //some validation if (affiliate.Address.CountryId == 0) { affiliate.Address.CountryId = null; } if (affiliate.Address.StateProvinceId == 0) { affiliate.Address.StateProvinceId = null; } _affiliateService.InsertAffiliate(affiliate); //activity log _customerActivityService.InsertActivity("AddNewAffiliate", string.Format(_localizationService.GetResource("ActivityLog.AddNewAffiliate"), affiliate.Id), affiliate); SuccessNotification(_localizationService.GetResource("Admin.Affiliates.Added")); return(continueEditing ? RedirectToAction("Edit", new { id = affiliate.Id }) : RedirectToAction("List")); } //prepare model model = _affiliateModelFactory.PrepareAffiliateModel(model, null, true); //if we got this far, something failed, redisplay form return(View(model)); }
public ActionResult Edit(AffiliateModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageAffiliates)) { return(AccessDeniedView()); } var affiliate = _affiliateService.GetAffiliateById(model.Id); if (affiliate == null || affiliate.Deleted) { //No affiliate found with the specified id return(RedirectToAction("List")); } if (ModelState.IsValid) { affiliate.Active = model.Active; affiliate.NickName = model.NickName; affiliate.Address = model.Address.ToEntity(affiliate.Address); //some validation if (affiliate.Address.CountryId == 0) { affiliate.Address.CountryId = null; } if (affiliate.Address.StateProvinceId == 0) { affiliate.Address.StateProvinceId = null; } _affiliateService.UpdateAffiliate(affiliate); SuccessNotification(_localizationService.GetResource("Admin.Affiliates.Updated")); if (continueEditing) { //selected tab SaveSelectedTabIndex(); return(RedirectToAction("Edit", affiliate.Id)); } else { return(RedirectToAction("List")); } } //If we got this far, something failed, redisplay form PrepareAffiliateModel(model, affiliate, true); return(View(model)); }
public ActionResult Edit(int id) { var affiliate = _affiliateService.GetAffiliateById(id); if (affiliate == null || affiliate.Deleted) { //No affiliate found with the specified id return(RedirectToAction("List")); } var model = new AffiliateModel(); PrepareAffiliateModel(model, affiliate, false); return(View(model)); }
public async Task <IActionResult> Edit(string id) { var affiliate = await _affiliateService.GetAffiliateById(id); if (affiliate == null || affiliate.Deleted) { //No affiliate found with the specified id return(RedirectToAction("List")); } var model = new AffiliateModel(); await _affiliateViewModelService.PrepareAffiliateModel(model, affiliate, false); return(View(model)); }
public virtual Affiliate InsertAffiliateModel(AffiliateModel model) { var affiliate = new Affiliate(); affiliate.Active = model.Active; affiliate.AdminComment = model.AdminComment; //validate friendly URL name var friendlyUrlName = affiliate.ValidateFriendlyUrlName(model.FriendlyUrlName); affiliate.FriendlyUrlName = friendlyUrlName; affiliate.Address = model.Address.ToEntity(); affiliate.Address.CreatedOnUtc = DateTime.UtcNow; //some validation _affiliateService.InsertAffiliate(affiliate); return(affiliate); }
public virtual async Task <Affiliate> InsertAffiliateModel(AffiliateModel model) { var affiliate = new Affiliate(); affiliate.Active = model.Active; affiliate.AdminComment = model.AdminComment; //validate friendly URL name var friendlyUrlName = await affiliate.ValidateFriendlyUrlName(_affiliateService, _seoSettings, model.FriendlyUrlName); affiliate.FriendlyUrlName = friendlyUrlName; affiliate.Address = model.Address.ToEntity(); affiliate.Address.CreatedOnUtc = DateTime.UtcNow; //some validation await _affiliateService.InsertAffiliate(affiliate); return(affiliate); }
public virtual async Task <(IEnumerable <AffiliateModel> affiliateModels, int totalCount)> PrepareAffiliateModelList(AffiliateListModel model, int pageIndex, int pageSize) { var affiliates = await _affiliateService.GetAllAffiliates(model.SearchFriendlyUrlName, model.SearchFirstName, model.SearchLastName, model.LoadOnlyWithOrders, model.OrdersCreatedFromUtc, model.OrdersCreatedToUtc, pageIndex - 1, pageSize, true); var affiliateModels = new List <AffiliateModel>(); foreach (var x in affiliates) { var m = new AffiliateModel(); await PrepareAffiliateModel(m, x, false, false); affiliateModels.Add(m); } return(affiliateModels, affiliates.TotalCount); }
/// <summary> /// Prepare affiliate model /// </summary> /// <param name="model">Affiliate model</param> /// <param name="affiliate">Affiliate</param> /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param> /// <returns> /// A task that represents the asynchronous operation /// The task result contains the affiliate model /// </returns> public virtual async Task <AffiliateModel> PrepareAffiliateModelAsync(AffiliateModel model, Affiliate affiliate, bool excludeProperties = false) { //fill in model values from the entity if (affiliate != null) { model ??= affiliate.ToModel <AffiliateModel>(); model.Url = await _affiliateService.GenerateUrlAsync(affiliate); //prepare nested search models await PrepareAffiliatedOrderSearchModelAsync(model.AffiliatedOrderSearchModel, affiliate); PrepareAffiliatedCustomerSearchModel(model.AffiliatedCustomerSearchModel, affiliate); //whether to fill in some of properties if (!excludeProperties) { model.AdminComment = affiliate.AdminComment; model.FriendlyUrlName = affiliate.FriendlyUrlName; model.Active = affiliate.Active; } } //prepare address model var address = await _addressService.GetAddressByIdAsync(affiliate?.AddressId ?? 0); if (!excludeProperties && address != null) { model.Address = address.ToModel(model.Address); } await _addressModelFactory.PrepareAddressModelAsync(model.Address, address); model.Address.FirstNameRequired = true; model.Address.LastNameRequired = true; model.Address.EmailRequired = true; model.Address.CountryRequired = true; model.Address.CountyRequired = true; model.Address.CityRequired = true; model.Address.StreetAddressRequired = true; model.Address.ZipPostalCodeRequired = true; model.Address.PhoneRequired = true; return(model); }
//edit public ActionResult Edit(int id) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageAffiliates)) { return(AccessDeniedView()); } var affiliate = _affiliateService.GetAffiliateById(id); if (affiliate == null || affiliate.Deleted) { throw new ArgumentException("No affiliate found with the specified id", "id"); } var model = new AffiliateModel(); PrepareAffiliateModel(model, affiliate, false); return(View(model)); }
//edit public virtual IActionResult Edit(int id) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageAffiliates)) { return(AccessDeniedView()); } var affiliate = _affiliateService.GetAffiliateById(id); if (affiliate == null || affiliate.Deleted) { //No affiliate found with the specified id return(RedirectToAction("List")); } var model = new AffiliateModel(); PrepareAffiliateModel(model, affiliate, false, true, true); return(View(model)); }