/// <returns>A task that represents the asynchronous operation</returns> protected virtual async Task UpdateLocalesAsync(DeliveryDate deliveryDate, DeliveryDateModel model) { foreach (var localized in model.Locales) { await _localizedEntityService.SaveLocalizedValueAsync(deliveryDate, x => x.Name, localized.Name, localized.LanguageId); } }
public virtual IActionResult CreateDeliveryDate(DeliveryDateModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageShippingSettings)) { return(AccessDeniedView()); } if (ModelState.IsValid) { var deliveryDate = model.ToEntity <DeliveryDate>(); _dateRangeService.InsertDeliveryDate(deliveryDate); //locales UpdateLocales(deliveryDate, model); SuccessNotification(_localizationService.GetResource("Admin.Configuration.Shipping.DeliveryDates.Added")); return(continueEditing ? RedirectToAction("EditDeliveryDate", new { id = deliveryDate.Id }) : RedirectToAction("DatesAndRanges")); } //prepare model model = _shippingModelFactory.PrepareDeliveryDateModel(model, null, true); //if we got this far, something failed, redisplay form return(View(model)); }
public virtual async Task <IActionResult> EditDeliveryDate(DeliveryDateModel model, bool continueEditing) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageShippingSettings)) { return(AccessDeniedView()); } //try to get a delivery date with the specified id var deliveryDate = await _dateRangeService.GetDeliveryDateByIdAsync(model.Id); if (deliveryDate == null) { return(RedirectToAction("DatesAndRanges")); } if (ModelState.IsValid) { deliveryDate = model.ToEntity(deliveryDate); await _dateRangeService.UpdateDeliveryDateAsync(deliveryDate); //locales await UpdateLocalesAsync(deliveryDate, model); _notificationService.SuccessNotification(await _localizationService.GetResourceAsync("Admin.Configuration.Shipping.DeliveryDates.Updated")); return(continueEditing ? RedirectToAction("EditDeliveryDate", deliveryDate.Id) : RedirectToAction("DatesAndRanges")); } //prepare model model = await _shippingModelFactory.PrepareDeliveryDateModelAsync(model, deliveryDate, true); //if we got this far, something failed, redisplay form return(View(model)); }
public virtual IActionResult EditDeliveryDate(DeliveryDateModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageShippingSettings)) { return(AccessDeniedView()); } var deliveryDate = _dateRangeService.GetDeliveryDateById(model.Id); if (deliveryDate == null) { //No delivery date found with the specified id return(RedirectToAction("DatesAndRanges")); } if (ModelState.IsValid) { deliveryDate = model.ToEntity(deliveryDate); _dateRangeService.UpdateDeliveryDate(deliveryDate); //locales UpdateLocales(deliveryDate, model); SuccessNotification(_localizationService.GetResource("Admin.Configuration.Shipping.DeliveryDates.Updated")); return(continueEditing ? RedirectToAction("EditDeliveryDate", deliveryDate.Id) : RedirectToAction("DatesAndRanges")); } //If we got this far, something failed, redisplay form return(View(model)); }
protected virtual void UpdateLocales(DeliveryDate deliveryDate, DeliveryDateModel model) { foreach (var localized in model.Locales) { _localizedEntityService.SaveLocalizedValue(deliveryDate, x => x.Name, localized.Name, localized.LanguageId); } }
public ActionResult CreateDeliveryDate(DeliveryDateModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageShippingSettings)) { return(AccessDeniedView()); } if (ModelState.IsValid) { var deliveryDate = model.ToEntity(); deliveryDate.Locales = UpdateLocales(deliveryDate, model); //ensure valid color is chosen/entered if (!String.IsNullOrEmpty(model.ColorSquaresRgb)) { try { //ensure color is valid (can be instanciated) System.Drawing.ColorTranslator.FromHtml(model.ColorSquaresRgb); } catch (Exception exc) { ModelState.AddModelError("", exc.Message); } } _shippingService.InsertDeliveryDate(deliveryDate); SuccessNotification(_localizationService.GetResource("Admin.Configuration.Shipping.DeliveryDates.Added")); return(continueEditing ? RedirectToAction("EditDeliveryDate", new { id = deliveryDate.Id }) : RedirectToAction("DeliveryDates")); } //If we got this far, something failed, redisplay form return(View(model)); }
public IActionResult CreateDeliveryDate() { var model = new DeliveryDateModel(); model.ColorSquaresRgb = "#000000"; //locales AddLocales(_languageService, model.Locales); return(View(model)); }
public async Task <IActionResult> CreateDeliveryDate() { var model = new DeliveryDateModel { ColorSquaresRgb = "#000000" }; //locales await AddLocales(_languageService, model.Locales); return(View(model)); }
public IActionResult CreateDeliveryDate(DeliveryDateModel model, bool continueEditing) { if (ModelState.IsValid) { var deliveryDate = model.ToEntity(); _shippingService.InsertDeliveryDate(deliveryDate); SuccessNotification(_localizationService.GetResource("Admin.Configuration.Shipping.DeliveryDates.Added")); return(continueEditing ? RedirectToAction("EditDeliveryDate", new { id = deliveryDate.Id }) : RedirectToAction("DeliveryDates")); } //If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult CreateDeliveryDate() { if (!_permissionService.Authorize(StandardPermissionProvider.ManageShippingSettings)) { return(AccessDeniedView()); } var model = new DeliveryDateModel(); //locales AddLocales(_languageService, model.Locales); return(View(model)); }
public IActionResult EditDeliveryDate(DeliveryDateModel model, bool continueEditing) { var deliveryDate = _shippingService.GetDeliveryDateById(model.Id); if (deliveryDate == null) { //No delivery date found with the specified id return(RedirectToAction("DeliveryDates")); } if (ModelState.IsValid) { deliveryDate = model.ToEntity(deliveryDate); _shippingService.UpdateDeliveryDate(deliveryDate); //locales SuccessNotification(_localizationService.GetResource("Admin.Configuration.Shipping.DeliveryDates.Updated")); return(continueEditing ? RedirectToAction("EditDeliveryDate", new { id = deliveryDate.Id }) : RedirectToAction("DeliveryDates")); } //If we got this far, something failed, redisplay form return(View(model)); }
/// <summary> /// Prepare delivery date model /// </summary> /// <param name="model">Delivery date model</param> /// <param name="deliveryDate">Delivery date</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 delivery date model /// </returns> public virtual async Task <DeliveryDateModel> PrepareDeliveryDateModelAsync(DeliveryDateModel model, DeliveryDate deliveryDate, bool excludeProperties = false) { Action <DeliveryDateLocalizedModel, int> localizedModelConfiguration = null; if (deliveryDate != null) { //fill in model values from the entity model ??= deliveryDate.ToModel <DeliveryDateModel>(); //define localized model configuration action localizedModelConfiguration = async(locale, languageId) => { locale.Name = await _localizationService.GetLocalizedAsync(deliveryDate, entity => entity.Name, languageId, false, false); }; } //prepare localized models if (!excludeProperties) { model.Locales = await _localizedModelFactory.PrepareLocalizedModelsAsync(localizedModelConfiguration); } return(model); }
/// <summary> /// Prepare delivery date model /// </summary> /// <param name="model">Delivery date model</param> /// <param name="deliveryDate">Delivery date</param> /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param> /// <returns>Delivery date model</returns> public virtual DeliveryDateModel PrepareDeliveryDateModel(DeliveryDateModel model, DeliveryDate deliveryDate, bool excludeProperties = false) { Action <DeliveryDateLocalizedModel, int> localizedModelConfiguration = null; if (deliveryDate != null) { //fill in model values from the entity model = model ?? deliveryDate.ToModel(); //define localized model configuration action localizedModelConfiguration = (locale, languageId) => { locale.Name = deliveryDate.GetLocalized(entity => entity.Name, languageId, false, false); }; } //prepare localized models if (!excludeProperties) { model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration); } return(model); }
public ActionResult CreateDeliveryDate() { if (!_permissionService.Authorize(StandardPermissionProvider.ManageShippingSettings)) return AccessDeniedView(); var model = new DeliveryDateModel(); //locales AddLocales(_languageService, model.Locales); return View(model); }
public static DeliveryDate ToEntity(this DeliveryDateModel model) { return(model.MapTo <DeliveryDateModel, DeliveryDate>()); }
public static DeliveryDate ToEntity(this DeliveryDateModel model, DeliveryDate destination) { return(model.MapTo(destination)); }
protected virtual List<LocalizedProperty> UpdateLocales(DeliveryDate deliveryDate, DeliveryDateModel model) { List<LocalizedProperty> localized = new List<LocalizedProperty>(); foreach (var local in model.Locales) { localized.Add(new LocalizedProperty() { LanguageId = local.LanguageId, LocaleKey = "Name", LocaleValue = local.Name }); } return localized; }
protected virtual List <LocalizedProperty> UpdateLocales(DeliveryDate deliveryDate, DeliveryDateModel model) { List <LocalizedProperty> localized = new List <LocalizedProperty>(); foreach (var local in model.Locales) { localized.Add(new LocalizedProperty() { LanguageId = local.LanguageId, LocaleKey = "Name", LocaleValue = local.Name }); } return(localized); }
public static DeliveryDate ToEntity(this DeliveryDateModel model) { return(Mapper.Map <DeliveryDateModel, DeliveryDate>(model)); }
public static DeliveryDate ToEntity(this DeliveryDateModel model, DeliveryDate destination) { return(Mapper.Map(model, destination)); }
public ActionResult CreateDeliveryDate(DeliveryDateModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageShippingSettings)) return AccessDeniedView(); if (ModelState.IsValid) { var deliveryDate = model.ToEntity(); _shippingService.InsertDeliveryDate(deliveryDate); //locales UpdateLocales(deliveryDate, model); SuccessNotification(_localizationService.GetResource("Admin.Configuration.Shipping.DeliveryDates.Added")); return continueEditing ? RedirectToAction("EditDeliveryDate", new { id = deliveryDate.Id }) : RedirectToAction("DeliveryDates"); } //If we got this far, something failed, redisplay form return View(model); }
public ActionResult EditDeliveryDate(DeliveryDateModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageShippingSettings)) return AccessDeniedView(); var deliveryDate = _shippingService.GetDeliveryDateById(model.Id); if (deliveryDate == null) //No delivery date found with the specified id return RedirectToAction("DeliveryDates"); if (ModelState.IsValid) { deliveryDate = model.ToEntity(deliveryDate); _shippingService.UpdateDeliveryDate(deliveryDate); //locales UpdateLocales(deliveryDate, model); SuccessNotification(_localizationService.GetResource("Admin.Configuration.Shipping.DeliveryDates.Updated")); return continueEditing ? RedirectToAction("EditDeliveryDate", deliveryDate.Id) : RedirectToAction("DeliveryDates"); } //If we got this far, something failed, redisplay form return View(model); }
public ActionResult EditDeliveryDate(DeliveryDateModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageShippingSettings)) return AccessDeniedView(); var deliveryDate = _shippingService.GetDeliveryDateById(model.Id); if (deliveryDate == null) //No delivery date found with the specified id return RedirectToAction("DeliveryDates"); //ensure valid color is chosen/entered if (!String.IsNullOrEmpty(model.ColorSquaresRgb)) { try { //ensure color is valid (can be instanciated) System.Drawing.ColorTranslator.FromHtml(model.ColorSquaresRgb); } catch (Exception exc) { ModelState.AddModelError("", exc.Message); } } if (ModelState.IsValid) { deliveryDate = model.ToEntity(deliveryDate); deliveryDate.Locales = UpdateLocales(deliveryDate, model); _shippingService.UpdateDeliveryDate(deliveryDate); //locales SuccessNotification(_localizationService.GetResource("Admin.Configuration.Shipping.DeliveryDates.Updated")); return continueEditing ? RedirectToAction("EditDeliveryDate", deliveryDate.Id) : RedirectToAction("DeliveryDates"); } //If we got this far, something failed, redisplay form return View(model); }