Exemple #1
0
        public ActionResult Edit(int id)
        {
            if (!_permissionService.Authorize("ManageDataTokens"))
            {
                return(AccessDeniedView());
            }

            var model = new CreateTemplateModel.CreateDataTokensModel();
            var user  = _userContext.CurrentUser;

            if (id == 0)
            {
                throw new Exception("Data Token Id Missing");
            }

            var temp = _templateService.GetDataTokenById(id);

            model = new CreateTemplateModel.CreateDataTokensModel
            {
                Name            = temp.Name,
                SystemName      = temp.SystemName,
                Value           = temp.Value,
                Id              = temp.Id,
                UserId          = temp.UserId,
                IsSystemDefined = temp.IsSystemDefined
            };

            return(View(model));
        }
Exemple #2
0
        public ActionResult Create()
        {
            if (!_permissionService.Authorize("ManageDataTokens"))
            {
                return(AccessDeniedView());
            }

            var model = new CreateTemplateModel.CreateDataTokensModel();

            return(View(model));
        }
Exemple #3
0
        public ActionResult Edit(CreateTemplateModel.CreateDataTokensModel model)
        {
            if (!_permissionService.Authorize("ManageDataTokens"))
            {
                return(AccessDeniedView());
            }

            var user = _userContext.CurrentUser;
            // Check for duplicate tokens, if any
            var token = _templateService.GetDataTokenByName(model.Name);

            if (token != null && token.Id != model.Id)
            {
                ModelState.AddModelError("Name", "A Data Token with the same name already exists. Please choose a different name.");
            }

            if (ModelState.IsValid)
            {
                var temp = _templateService.GetDataTokenById(model.Id);
                if (temp != null)
                {
                    temp.CreatedOn       = DateTime.Now;
                    temp.Name            = model.Name;
                    temp.SystemName      = model.SystemName;
                    temp.Value           = model.Value;
                    temp.Id              = model.Id;
                    temp.ModifiedOn      = DateTime.Now;
                    temp.IsSystemDefined = model.IsSystemDefined;
                    _templateService.Update(temp);
                    return(RedirectToAction("DataTokens"));
                }
            }
            else
            {
                ErrorNotification("An error occured while creating event. Please try again.");
                return(View(model));
            }

            SuccessNotification("Data token updated successfully");
            return(RedirectToAction("DataTokens"));
        }
Exemple #4
0
        public ActionResult Create(CreateTemplateModel.CreateDataTokensModel model)
        {
            if (!_permissionService.Authorize("ManageDataTokens"))
            {
                return(AccessDeniedView());
            }

            var user = _userContext.CurrentUser;
            // Check for duplicate tokens, if any
            var checktoken = _templateService.GetDataTokenByName(model.Name);

            if (checktoken != null)
            {
                ModelState.AddModelError("Name", "A Data Token with the same name already exists. Please choose a different name.");
            }

            if (ModelState.IsValid)
            {
                var token = new DataToken
                {
                    Value           = model.Value,
                    Name            = model.Name,
                    SystemName      = model.SystemName,
                    UserId          = user.Id,
                    IsDeleted       = false,
                    CreatedOn       = DateTime.Now,
                    ModifiedOn      = DateTime.Now,
                    IsSystemDefined = model.IsSystemDefined
                };
                _templateService.Insert(token);
            }
            else
            {
                ErrorNotification("An error occured while creating event. Please try again.");
                return(View(model));
            }

            SuccessNotification("Data Token saved successfully.");
            return(RedirectToAction("DataTokens"));
        }