public virtual IActionResult Create(ReviewTypeModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings)) { return(AccessDeniedView()); } if (ModelState.IsValid) { var reviewType = model.ToEntity <ReviewType>(); _reviewTypeService.InsertReviewType(reviewType); //activity log _customerActivityService.InsertActivity("AddNewReviewType", string.Format(_localizationService.GetResource("ActivityLog.AddNewReviewType"), reviewType.Id), reviewType); //locales UpdateReviewTypeLocales(reviewType, model); _notificationService.SuccessNotification(_localizationService.GetResource("Admin.Settings.ReviewType.Added")); return(continueEditing ? RedirectToAction("Edit", new { id = reviewType.Id }) : RedirectToAction("List")); } //prepare model model = _reviewTypeModelFactory.PrepareReviewTypeModel(model, null, true); //if we got this far, something failed, redisplay form return(View(model)); }
/// <summary> /// Prepare review type model /// </summary> /// <param name="model">Review type model</param> /// <param name="reviewType">Review type</param> /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param> /// <returns>Review type model</returns> public virtual ReviewTypeModel PrepareReviewTypeModel(ReviewTypeModel model, ReviewType reviewType, bool excludeProperties = false) { Action <ReviewTypeLocalizedModel, int> localizedModelConfiguration = null; if (reviewType != null) { //fill in model values from the entity model = model ?? reviewType.ToModel <ReviewTypeModel>(); //define localized model configuration action localizedModelConfiguration = (locale, languageId) => { locale.Name = _localizationService.GetLocalized(reviewType, entity => entity.Name, languageId, false, false); locale.Description = _localizationService.GetLocalized(reviewType, entity => entity.Description, languageId, false, false); }; } //prepare localized models if (!excludeProperties) { model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration); } return(model); }
/// <summary> /// Prepare review type model /// </summary> /// <param name="model">Review type model</param> /// <param name="reviewType">Review type</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 review type model /// </returns> public virtual async Task <ReviewTypeModel> PrepareReviewTypeModelAsync(ReviewTypeModel model, ReviewType reviewType, bool excludeProperties = false) { Func <ReviewTypeLocalizedModel, int, Task> localizedModelConfiguration = null; if (reviewType != null) { //fill in model values from the entity model ??= reviewType.ToModel <ReviewTypeModel>(); //define localized model configuration action localizedModelConfiguration = async(locale, languageId) => { locale.Name = await _localizationService.GetLocalizedAsync(reviewType, entity => entity.Name, languageId, false, false); locale.Description = await _localizationService.GetLocalizedAsync(reviewType, entity => entity.Description, languageId, false, false); }; } //prepare localized models if (!excludeProperties) { model.Locales = await _localizedModelFactory.PrepareLocalizedModelsAsync(localizedModelConfiguration); } return(model); }
protected virtual void UpdateReviewTypeLocales(ReviewType reviewType, ReviewTypeModel model) { foreach (var localized in model.Locales) { _localizedEntityService.SaveLocalizedValue(reviewType, x => x.Name, localized.Name, localized.LanguageId); _localizedEntityService.SaveLocalizedValue(reviewType, x => x.Description, localized.Description, localized.LanguageId); } }
public virtual async Task <IActionResult> Edit(ReviewTypeModel model, bool continueEditing) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageSettings)) { return(AccessDeniedView()); } //try to get an review type with the specified id var reviewType = await _reviewTypeService.GetReviewTypeByIdAsync(model.Id); if (reviewType == null) { return(RedirectToAction("List")); } if (ModelState.IsValid) { reviewType = model.ToEntity(reviewType); await _reviewTypeService.UpdateReviewTypeAsync(reviewType); //activity log await _customerActivityService.InsertActivityAsync("EditReviewType", string.Format(await _localizationService.GetResourceAsync("ActivityLog.EditReviewType"), reviewType.Id), reviewType); //locales await UpdateReviewTypeLocalesAsync(reviewType, model); _notificationService.SuccessNotification(await _localizationService.GetResourceAsync("Admin.Settings.ReviewType.Updated")); return(continueEditing ? RedirectToAction("Edit", new { id = reviewType.Id }) : RedirectToAction("List")); } //prepare model model = await _reviewTypeModelFactory.PrepareReviewTypeModelAsync(model, reviewType, true); //if we got this far, something failed, redisplay form return(View(model)); }
/// <returns>A task that represents the asynchronous operation</returns> protected virtual async Task UpdateReviewTypeLocalesAsync(ReviewType reviewType, ReviewTypeModel model) { foreach (var localized in model.Locales) { await _localizedEntityService.SaveLocalizedValueAsync(reviewType, x => x.Name, localized.Name, localized.LanguageId); await _localizedEntityService.SaveLocalizedValueAsync(reviewType, x => x.Description, localized.Description, localized.LanguageId); } }