Exemplo n.º 1
0
        public DtoActionResult Put(int id, EntityCustomAssetType customAssetType)
        {
            customAssetType.Id = id;
            var result = _serviceCustomAssetType.Update(customAssetType);

            if (result == null)
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
            }
            return(result);
        }
Exemplo n.º 2
0
        public DtoActionResult Add(EntityCustomAssetType assetType)
        {
            var actionResult = new DtoActionResult();

            var validationResult = Validate(assetType,true);
            if (validationResult.Success)
            {
                _uow.CustomAssetTypeRepository.Insert(assetType);
                _uow.Save();
                actionResult.Success = true;
                actionResult.Id = assetType.Id;
            }
            else
            {
                return new DtoActionResult() {ErrorMessage = validationResult.ErrorMessage};
            }

            return actionResult;
        }
Exemplo n.º 3
0
        protected void buttonAdd_OnClick(object sender, EventArgs e)
        {
            var assetType = new EntityCustomAssetType();

            assetType.Name        = txtName.Text;
            assetType.Description = txtDescription.Text;

            var result = Call.CustomAssetTypeApi.Post(assetType);

            if (result.Success)
            {
                EndUserMessage = "Successfully Created Asset Type";
                Response.Redirect("~/views/assets/assettypes/edit.aspx?level=2&assetTypeId=" + result.Id);
            }
            else
            {
                EndUserMessage = result.ErrorMessage;
            }
        }
Exemplo n.º 4
0
        public DtoActionResult Update(EntityCustomAssetType customAssetType)
        {
            var u = GetCustomAssetType(customAssetType.Id);
            if (u == null) return new DtoActionResult {ErrorMessage = "Custom Asset Type Not Found", Id = 0};
            if (u.Id < 0) return new DtoActionResult { ErrorMessage = "Built-In Usage Types Cannot Be Modified", Id = 0 };
            var actionResult = new DtoActionResult();

               var validationResult = Validate(customAssetType,false);
            if (validationResult.Success)
            {
                _uow.CustomAssetTypeRepository.Update(customAssetType, u.Id);
                _uow.Save();
                actionResult.Success = true;
                actionResult.Id = customAssetType.Id;
            }
            else
            {
                return new DtoActionResult() {ErrorMessage = validationResult.ErrorMessage};
            }
            return actionResult;
        }
Exemplo n.º 5
0
        public DtoValidationResult Validate(EntityCustomAssetType assetType,bool isNew)
        {
            var validationResult = new DtoValidationResult { Success = true };

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

            if (isNew)
            {
                if (_uow.CustomAssetTypeRepository.Exists(h => h.Name == assetType.Name))
                {
                    validationResult.Success = false;
                    validationResult.ErrorMessage = "An Asset Type With This Name Already Exists";
                    return validationResult;
                }
            }
            else
            {
                var original = _uow.CustomAssetTypeRepository.GetById(assetType.Id);
                if (original.Name != assetType.Name)
                {
                    if (_uow.CustomAssetTypeRepository.Exists(h => h.Name == assetType.Name))
                    {
                        validationResult.Success = false;
                        validationResult.ErrorMessage = "An Asset Type With This Name Already Exists";
                        return validationResult;
                    }
                }
            }

            return validationResult;
        }
Exemplo n.º 6
0
 public DtoActionResult Post(EntityCustomAssetType customAssetType)
 {
     return(_serviceCustomAssetType.Add(customAssetType));
 }