public DtoActionResult Update(EntityAssetGroup assetGroup) { var u = GetAssetGroup(assetGroup.Id); if (u == null) { return new DtoActionResult { ErrorMessage = "Asset Group Not Found", Id = 0 } } ; var actionResult = new DtoActionResult(); var validationResult = Validate(assetGroup, false); if (validationResult.Success) { _uow.AssetGroupRepository.Update(assetGroup, u.Id); _uow.Save(); actionResult.Success = true; actionResult.Id = assetGroup.Id; } else { return(new DtoActionResult() { ErrorMessage = validationResult.ErrorMessage }); } return(actionResult); }
public DtoActionResult Put(int id, EntityAssetGroup assetGroup) { assetGroup.Id = id; var result = _serviceAssetGroup.Update(assetGroup); if (result == null) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound)); } return(result); }
protected void buttonAdd_OnClick(object sender, EventArgs e) { var assetGroup = new EntityAssetGroup(); assetGroup.Name = txtName.Text; assetGroup.Description = txtDescription.Text; var result = Call.AssetGroupApi.Post(assetGroup); if (result.Success) { EndUserMessage = "Successfully Created Asset Group"; Response.Redirect("~/views/assets/assetgroups/edit.aspx?level=2&assetGroupId=" + result.Id); } else { EndUserMessage = result.ErrorMessage; } }
public DtoValidationResult Validate(EntityAssetGroup assetGroup, bool isNew) { var validationResult = new DtoValidationResult { Success = true }; if (string.IsNullOrEmpty(assetGroup.Name) || !assetGroup.Name.All(c => char.IsLetterOrDigit(c) || c == '_' || c == '-' || c == ' ')) { validationResult.Success = false; validationResult.ErrorMessage = "Asset Group Name Is Not Valid"; return(validationResult); } if (isNew) { if (_uow.AssetGroupRepository.Exists(h => h.Name == assetGroup.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "An Asset Group With This Name Already Exists"; return(validationResult); } } else { var original = _uow.AssetGroupRepository.GetById(assetGroup.Id); if (original.Name != assetGroup.Name) { if (_uow.AssetGroupRepository.Exists(h => h.Name == assetGroup.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "An Asset Group With This Name Already Exists"; return(validationResult); } } } return(validationResult); }
public DtoActionResult Add(EntityAssetGroup assetGroupType) { var actionResult = new DtoActionResult(); var validationResult = Validate(assetGroupType, true); if (validationResult.Success) { _uow.AssetGroupRepository.Insert(assetGroupType); _uow.Save(); actionResult.Success = true; actionResult.Id = assetGroupType.Id; } else { return(new DtoActionResult() { ErrorMessage = validationResult.ErrorMessage }); } return(actionResult); }
public DtoActionResult Post(EntityAssetGroup assetGroup) { return(_serviceAssetGroup.Add(assetGroup)); }