public virtual TaskAttributeValueModel PrepareTaskAttributeValueModel(TaskAttributeValueModel model,
                                                                              TaskAttribute taskAttribute, TaskAttributeValue taskAttributeValue, bool excludeProperties = false)
        {
            if (taskAttribute == null)
            {
                throw new ArgumentNullException(nameof(taskAttribute));
            }

            Action <TaskAttributeValueLocalizedModel, int> localizedModelConfiguration = null;

            if (taskAttributeValue != null)
            {
                //fill in model values from the entity
                model = model ?? taskAttributeValue.ToModel <TaskAttributeValueModel>();

                //define localized model configuration action
                localizedModelConfiguration = (locale, languageId) =>
                {
                    locale.Name = _localizationService.GetLocalized(taskAttributeValue, entity => entity.Name, languageId, false, false);
                };
            }

            model.TaskAttributeId = taskAttribute.Id;

            if (!excludeProperties)
            {
                model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration);
            }

            return(model);
        }
Exemple #2
0
        public virtual IActionResult ValueEditPopup(TaskAttributeValueModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings))
            {
                return(AccessDeniedView());
            }

            //try to get a customer attribute value with the specified id
            var taskAttributeValue = _taskAttributeService.GetTaskAttributeValueById(model.Id);

            if (taskAttributeValue == null)
            {
                return(RedirectToAction("List"));
            }

            //try to get a customer attribute with the specified id
            var taskAttribute = _taskAttributeService.GetTaskAttributeById(taskAttributeValue.TaskAttributeId);

            if (taskAttribute == null)
            {
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                taskAttributeValue = model.ToEntity(taskAttributeValue);
                _taskAttributeService.UpdateTaskAttributeValue(taskAttributeValue);

                //activity log
                _customerActivityService.InsertActivity("EditTaskAttributeValue",
                                                        string.Format(_localizationService.GetResource("ActivityLog.EditTaskAttributeValue"), taskAttributeValue.Id),
                                                        taskAttributeValue);

                UpdateValueLocales(taskAttributeValue, model);

                ViewBag.RefreshPage = true;

                return(View(model));
            }

            //prepare model
            model = _taskAttributeModelFactory.PrepareTaskAttributeValueModel(model, taskAttribute, taskAttributeValue, true);

            //if we got this far, something failed, redisplay form
            return(View(model));
        }
Exemple #3
0
 protected virtual void UpdateValueLocales(TaskAttributeValue taskAttributeValue, TaskAttributeValueModel model)
 {
     foreach (var localized in model.Locales)
     {
         _localizedEntityService.SaveLocalizedValue(taskAttributeValue,
                                                    x => x.Name,
                                                    localized.Name,
                                                    localized.LanguageId);
     }
 }