public DtoActionResult Update(EntityCustomAttribute customAttribute)
        {
            var u = GetCustomAttribute(customAttribute.Id);

            if (u == null)
            {
                return new DtoActionResult {
                           ErrorMessage = "Custom Attribute Not Found", Id = 0
                }
            }
            ;

            var actionResult = new DtoActionResult();

            var validationResult = Validate(customAttribute, false);

            if (validationResult.Success)
            {
                _uow.CustomAttributeRepository.Update(customAttribute, u.Id);

                _uow.Save();
                actionResult.Success = true;
                actionResult.Id      = customAttribute.Id;
            }
            else
            {
                return(new DtoActionResult()
                {
                    ErrorMessage = validationResult.ErrorMessage
                });
            }
            return(actionResult);
        }
        public DtoActionResult Put(int id, EntityCustomAttribute customAttribute)
        {
            customAttribute.Id = id;
            var result = _serviceCustomAttribute.Update(customAttribute);

            if (result == null)
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
            }
            return(result);
        }
Exemple #3
0
 protected override void OnInit(EventArgs e)
 {
     base.OnInit(e);
     AssetType = !string.IsNullOrEmpty(Request.QueryString["assetTypeId"])
         ? Call.CustomAssetTypeApi.Get(Convert.ToInt32(Request.QueryString["assetTypeId"]))
         : null;
     Asset = !string.IsNullOrEmpty(Request.QueryString["assetId"])
         ? Call.AssetApi.Get(Convert.ToInt32(Request.QueryString["assetId"]))
         : null;
     AssetGroup = !string.IsNullOrEmpty(Request.QueryString["assetGroupId"])
         ? Call.AssetGroupApi.Get(Convert.ToInt32(Request.QueryString["assetGroupId"]))
         : null;
     CustomAttribute = !string.IsNullOrEmpty(Request["attributeId"])
       ? Call.CustomAttributeApi.Get(Convert.ToInt32(Request.QueryString["attributeId"]))
       : null;
 }
Exemple #4
0
        protected void buttonAdd_OnClick(object sender, EventArgs e)
        {
            var ca = new EntityCustomAttribute();

            ca.Name                   = txtName.Text;
            ca.Description            = txtDescription.Text;
            ca.TextMode               = (EnumCustomAttribute.TextMode)Enum.Parse(typeof(EnumCustomAttribute.TextMode), ddlTextMode.SelectedValue);
            ca.UsageType              = Convert.ToInt32(ddlUsageType.SelectedValue);
            ca.ClientImagingAvailable = chkImaging.Checked;
            var result = Call.CustomAttributeApi.Post(ca);

            if (!result.Success)
            {
                EndUserMessage = result.ErrorMessage;
            }
            else
            {
                EndUserMessage = "Successfully Created Custom Attribute";
                Response.Redirect("~/views/assets/attributes/edit.aspx?level=2&attributeId=" + result.Id);
            }
        }
        public DtoValidationResult Validate(EntityCustomAttribute customAttribute, bool isNew)
        {
            var validationResult = new DtoValidationResult {
                Success = true
            };

            if (string.IsNullOrEmpty(customAttribute.Name) || !customAttribute.Name.All(c => char.IsLetterOrDigit(c) || c == '_' || c == '-'))
            {
                validationResult.Success      = false;
                validationResult.ErrorMessage = "Custom Attribute Name Is Not Valid";
                return(validationResult);
            }

            if (isNew)
            {
                if (_uow.CustomAttributeRepository.Exists(h => h.Name == customAttribute.Name))
                {
                    validationResult.Success      = false;
                    validationResult.ErrorMessage = "A Custom Attribute With This Name Already Exists";
                    return(validationResult);
                }
            }
            else
            {
                var original = _uow.CustomAttributeRepository.GetById(customAttribute.Id);
                if (original.Name != customAttribute.Name)
                {
                    if (_uow.CategoryRepository.Exists(h => h.Name == customAttribute.Name))
                    {
                        validationResult.Success      = false;
                        validationResult.ErrorMessage = "A Custom Attribute With This Name Already Exists";
                        return(validationResult);
                    }
                }
            }

            return(validationResult);
        }
        public DtoActionResult Add(EntityCustomAttribute customAttribute)
        {
            var actionResult = new DtoActionResult();

            var validationResult = Validate(customAttribute, true);

            if (validationResult.Success)
            {
                _uow.CustomAttributeRepository.Insert(customAttribute);
                _uow.Save();
                actionResult.Success = true;
                actionResult.Id      = customAttribute.Id;
            }
            else
            {
                return(new DtoActionResult()
                {
                    ErrorMessage = validationResult.ErrorMessage
                });
            }

            return(actionResult);
        }
 public DtoActionResult Post(EntityCustomAttribute customAttribute)
 {
     return(_serviceCustomAttribute.Add(customAttribute));
 }