public ResourceDto NewResourceFromClipboard(bool contentInDB = false) { try { if (!Clipboard.GetDataObject().GetDataPresent(DataFormats.Bitmap)) { View.ShowInfo("You do not have any images on the Clipboard to insert into this note.", "KaNote"); return(null); } var bm = (Bitmap)Clipboard.GetDataObject().GetData(DataFormats.Bitmap); var converter = new ImageConverter(); var newResource = new ResourceDto(); newResource.ResourceId = Guid.NewGuid(); newResource.NoteId = Model.NoteId; newResource.ContentInDB = contentInDB; newResource.Description = "Image inserted from clipboard."; newResource.Order = 0; newResource.Name = "ClipboardImg_" + newResource.ResourceId.ToString() + ".png"; newResource.FileType = Store.ExtensionFileToFileType(".png"); newResource.Container = Service.RepositoryRef.ResourcesContainer + @"\" + DateTime.Now.Year.ToString(); newResource.ContentArrayBytes = (byte[])converter.ConvertTo(bm, typeof(byte[])); Service.Notes.ManageResourceContent(newResource); Model.Resources.Add(newResource); return(newResource); } catch (Exception ex) { View.ShowInfo($"Error: {ex.Message}"); return(null); } }
public void Update(ResourceDto item) { using (var ctx = ObjectContextManager <PTrackerEntities> .GetManager("PTrackerEntities")) { var data = (from r in ctx.ObjectContext.Resources where r.Id == item.Id select r).FirstOrDefault(); if (data == null) { throw new DataNotFoundException("Resource"); } if (!data.LastChanged.Matches(item.LastChanged)) { throw new ConcurrencyException("Resource"); } data.FirstName = item.FirstName; data.LastName = item.LastName; var count = ctx.ObjectContext.SaveChanges(); if (count == 0) { throw new UpdateFailureException("Resource"); } item.LastChanged = data.LastChanged; } }
// PUT api/values/5 public void Put(int id, [FromBody] ResourceDto value) { if (ModelState.IsValid && value.ID == id) { _service.Update(value); } }
// POST api/values public void Post([FromBody] ResourceDto value) { if (ModelState.IsValid) { _service.Create(value); } }
public async Task <bool> DeleteResource(Guid resourceId) { var resource = new ResourceEditorComponent(Store); resource.AutoDBSave = false; // don't save automatically var res = await resource.DeleteModel(Service, resourceId); if (res) { ResourceDto resDel = null; foreach (var item in Model.Resources) { if (item.ResourceId == resourceId) { resDel = item; break; } } if (resDel != null) { if (resDel.IsNew()) { Model.Resources.Remove(resDel); } else { resDel.SetIsDeleted(true); } } } return(res); }
/// <summary> /// 转换为资源实体 /// </summary> /// <param name="dto">资源数据传输对象</param> public static Resource ToEntity3(this ResourceDto dto) { if (dto == null) { return(new Resource()); } return(ResourceFactory.Create( resourceId: dto.Id.ToGuid(), uri: dto.Uri, name: dto.Name, type: dto.Type, note: dto.Note, isLeave: dto.IsLeave, parentId: dto.ParentId.ToGuidOrNull(), path: dto.Path, level: dto.Level.Value, sortId: dto.SortId, creationTime: dto.CreationTime, creatorId: dto.CreatorId, lastModificationTime: dto.LastModificationTime, lastModifierId: dto.LastModifierId, isDeleted: dto.IsDeleted, pinYin: dto.PinYin, enabled: dto.Enabled.Value, appId: dto.AppId, version: dto.Version )); }
/// <summary> /// 新增 /// </summary> /// <param name="entity"></param> /// <param name="array"></param> public void Add(ResourceDto entity, int[] array) { using (_unitOfWork) { var info = AutoMapperHelper.Signle <ResourceDto, Resource>(entity); var repository = _unitOfWork.Repository <Resource>(); if (array != null) { foreach (var item in array) { var operation = new Operation { OperationId = item }; info.Operations.Add(operation); } } repository.Add(info); _unitOfWork.Commit(); entity.ResourceId = info.ResourceId; } }
public void AddorUpdate(ResourceDto dto) { var entity = dto.MapTo <Resource>(); //var query = _resourceRepository.GetAllAsNoTracking(); //var model = query.SingleOrDefault(p => p.Id == entity.Id); var model = _resourceRepository.Find(entity.Id); Resource resourceParent = entity.ParentId == null ? null : _resourceRepository.Find((Guid)entity.ParentId); if (model == null) { entity.FixPathAndLevel(resourceParent); _resourceRepository.Add(entity); } else { model.FixPathAndLevel(resourceParent); //model.Id = entity.Id; model.ApplicationId = entity.ApplicationId; model.ParentId = entity.ParentId; model.Name = entity.Name; //model.Path = entity.Path; //model.Level = entity.Level; model.SortId = entity.SortId; model.Uri = entity.Uri; model.Type = entity.Type; model.Enabled = entity.Enabled; model.Version = entity.Version; _resourceRepository.Update(model); } }
public ActionResult Save(ResourceDto model) { var saveState = BusinessHelper.BuildSaveState(Request); var operationList = Request["OperationList"]; var array = BusinessHelper.BreakUpStr(operationList, ','); _resourceBll.HttpPostSave(model, saveState, array); var info = new AuthConfig { ControllerName = model.ControllerName, ResourceId = model.ResourceId, ResourceUrl = model.ResourceUrl, Roles = "" }; if (saveState.OperationState == OperationState.Add) { AuthConfigXmlHelper.AttachAuthConfigByXml(Api.PhysicsUrl + "/Config/AuthConfig.xml" , info); } else { AuthConfigXmlHelper.UpateResourceAuthConfigByXml(Api.PhysicsUrl + "/Config/AuthConfig.xml" , info); } return(RedirectToAction("Index", "Resource")); }
internal static ResourceDto AddRequiredLinks(this ResourceDto resource, Type targetResourceType, HttpContext context) { var urlHelperFactory = context.GetService <IUrlHelperFactory>(); var actionContextAccessor = context.GetService <IActionContextAccessor>(); var actionDescriptorCollectionProvider = context.GetService <IActionDescriptorCollectionProvider>(); var hateoasOptions = context.GetService <IOptions <HateoasOptions> >().Value; var urlHelper = urlHelperFactory.GetUrlHelper(actionContextAccessor.ActionContext); foreach (var link in hateoasOptions.RequiredLinks.Where(r => r.ResourceType == targetResourceType)) { if (!link.CheckAvailability(resource.Data)) { continue; } if (!(actionDescriptorCollectionProvider.ActionDescriptors.Items.FirstOrDefault(x => x.AttributeRouteInfo.Name == link.Name) is { } route)) { continue; } var routeValues = link.GetRouteValues(resource.Data); if (!(urlHelper.Link(link.Name, routeValues)?.ToLower() is { } url)) { continue; } var method = route.ActionConstraints.OfType <HttpMethodActionConstraint>().First().HttpMethods.First(); resource.Links.Add(new LinkDto(link.Name, url, method)); } return(resource); }
public async Task UpdateAsync(ResourceDto resourceDto) { var resouce = DtoModelMapping.Mapper.Map <Resource>(resourceDto); this._unitOfWork.ResourceRepository.Update(resouce); await this._unitOfWork.SaveChangesAsync(); }
private async void UpdatePreviewResource(ResourceDto resource) { _selectedResource = resource; if (webViewResource.Visible) { await webViewResource.NavigateToString(" "); } textDescriptionResource.Text = ""; if (_selectedResource == null) { return; } textDescriptionResource.Text = _selectedResource.Description; if (_com.Store.IsSupportedFileTypeForPreview(_selectedResource.FileType)) { webViewResource.Visible = true; panelPreview.Visible = false; await webViewResource.Navigate(_selectedResource.FullUrl); } else { _com.Service.Notes.ManageResourceContent(_selectedResource, false); webViewResource.Visible = false; panelPreview.Visible = true; linkViewFile.Visible = true; } }
public void Add_Resource_To_Part() { IPartsService repo = new PartsService(new BadgerDataModel()); PartDetailDTO part = new PartDetailDTO(); part.UnitCost = 1.25m; part.ItemDescription = "Master Widjet 1023"; part.ItemName = "MW-1023"; part.PartNum = "MW-10034"; part.MarkUp = 1.25m; part.Waste = 2.0m; part.Weight = 12.25m; part.UID = 1; part.ManuId = 245; part.Location = "AC23"; part.Obsolete = false; part.Sku = "1023847A990"; ResourceDto resource = new ResourceDto { ResourceDescription = "Chipman Home Network", CurrentVersion = 1, Data = File.ReadAllBytes(@"C:\Users\Rich.DESIGNSYNTHESIS\Documents\chipmanHomeNetwork.sdr") }; part.Resources.Add(resource); repo.InsertOrUpdate(part, "Richard Young"); Assert.IsTrue(1 == 1); }
private async void buttonResourceDelete_Click(object sender, EventArgs e) { if (listViewResources.SelectedItems.Count == 0) { MessageBox.Show("There is no task selected .", "KaNote"); return; } var delRes = listViewResources.SelectedItems[0].Name; var res = await _com.DeleteResource(Guid.Parse(delRes)); if (res) { listViewResources.Items[delRes].Remove(); _selectedResource = null; await webViewResource.NavigateToString(" "); webViewResource.Visible = false; panelPreview.Visible = true; textDescriptionResource.Text = ""; if (listViewResources.Items.Count > 0) { listViewResources.Items[0].Selected = true; } } }
/// <summary> /// 转换为资源实体 /// </summary> /// <param name="dto">资源数据传输对象</param> public static Resource ToEntity2(this ResourceDto dto) { if (dto == null) { return(new Resource()); } return(new Resource(dto.Id.ToGuid(), "", 1) { Uri = dto.Uri, Name = dto.Name, Type = dto.Type, Note = dto.Note, IsLeave = dto.IsLeave, ParentId = dto.ParentId.ToGuidOrNull(), SortId = dto.SortId, CreationTime = dto.CreationTime, CreatorId = dto.CreatorId, LastModificationTime = dto.LastModificationTime, LastModifierId = dto.LastModifierId, IsDeleted = dto.IsDeleted, PinYin = dto.PinYin, Enabled = dto.Enabled.Value, AppId = dto.AppId, Version = dto.Version, }); }
public void Add(ResourceDto resourceDto) { var newResource = _mapper.Map <Resource>(resourceDto); _databaseContext.Resources.Add(newResource); _databaseContext.SaveChanges(); }
public bool ManageResourceContent(ResourceDto resource, bool forceUpdateDto = true) { if (resource == null) { return(false); } string rootCacheResource = _repository.RespositoryRef.ResourcesContainerCacheRootPath; if (string.IsNullOrEmpty(resource.Container)) { if (forceUpdateDto) { resource.Container = _repository.RespositoryRef.ResourcesContainer + @"\" + DateTime.Now.Year.ToString(); resource.ContentInDB = _repository.RespositoryRef.ResourceContentInDB; } } if (rootCacheResource == null || resource.Container == null || resource.Name == null) { return(false); } try { string dirPath = Path.Combine(new string[] { rootCacheResource, resource.Container }); string file = GetResourcePath(resource); if (resource.ContentArrayBytes != null) { if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); } if (!File.Exists(file)) { File.WriteAllBytes(file, resource.ContentArrayBytes); } } if (forceUpdateDto) { if (!resource.ContentInDB) { resource.ContentArrayBytes = File.ReadAllBytes(file); } (resource.RelativeUrl, resource.FullUrl) = GetResourceUrls(resource); } } catch (Exception ex) { // TODO: anotate this meesage in log var errMsg = ex.ToString(); return(false); } return(true); }
/// <summary> /// 查询实体 /// </summary> /// <param name="saveState"></param> /// <returns></returns> public ResourceDto Query(SaveState saveState) { var resourceDto = new ResourceDto(); return(saveState.OperationState == OperationState.Add ? resourceDto : _resourceService.Query(saveState.Key, "Operations")); }
/// <summary> /// 转换为资源实体 /// </summary> /// <param name="dto">资源数据传输对象</param> public static Resource ToEntity(this ResourceDto dto) { if (dto == null) { return(new Resource()); } return(dto.MapTo(new Resource(dto.Id.ToGuid(), "", 1))); }
public void CreateResource(ResourceDto resource) { var entity = (Resource) new Resource().InjectFrom(resource); entity.Id = 0; _resourceRepository.Insert(entity); _unitOfWork.Save(); }
public async Task <int> CreateAsync(ResourceDto resourceDto) { var resouce = DtoModelMapping.Mapper.Map <Resource>(resourceDto); this._unitOfWork.ResourceRepository.Add(resouce); await this._unitOfWork.SaveChangesAsync(); return(resouce.Id); }
public void Create(ResourceDto resource) { if (resource == null) { throw new ArgumentNullException(nameof(ResourceDto)); } repository.Add(new DataLayer.Entities.Resource().InjectFrom(resource) as DataLayer.Entities.Resource); unit.Commit(); }
private static string SerializeHateoasData(ResourceDto dataWithHateoas) { return(JsonConvert.SerializeObject(dataWithHateoas, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver(), NullValueHandling = NullValueHandling.Ignore, ReferenceLoopHandling = ReferenceLoopHandling.Ignore })); }
private ListViewItem ResourceDtoToListViewItem(ResourceDto resource) { var itemList = new ListViewItem(resource.NameOut); itemList.Name = resource.ResourceId.ToString(); itemList.SubItems.Add(resource.FileType); itemList.SubItems.Add(resource.Order.ToString()); return(itemList); }
private void UpdateResource(ResourceDto resource) { var item = listViewResources.Items[resource.ResourceId.ToString()]; item.Text = resource.NameOut; item.SubItems[1].Text = resource.FileType; item.SubItems[2].Text = resource.Order.ToString(); UpdatePreviewResource(resource); }
public static VmResourceTreeGrid ToTreeGridVm(this ResourceDto dto) { VmResourceTreeGrid vmRoleGrid = dto.MapTo <VmResourceTreeGrid>(); vmRoleGrid.Type = dto.Type.ToString(); vmRoleGrid.CreationTime = dto.CreationTime.ToChineseDateTimeString(); vmRoleGrid.attributes = new { url = vmRoleGrid.Uri }; return(vmRoleGrid); }
public void Create(ResourceDto resourceDto) { if (resourceDto == null) { throw new BadRequestException("Resource cannot be null."); } _resourceRepository.Create(resourceDto.ToEntity()); }
public async Task <ActionResult <Resource> > Resource([FromBody] ResourceDto resourceDto) { var resource = _mapper.Map <ResourceDto, Resource>(resourceDto); _unitOfWork.Repository <Resource>().Add(resource); await _unitOfWork.Complete(); return(Ok(resourceDto)); }
public async Task <ResourceDto> GetAsync(long id) { LocalResource entity = await _resourceRepository.Select .Where(a => a.Id == id).ToOneAsync(); ResourceDto resourceDto = _mapper.Map <ResourceDto>(entity); return(resourceDto); }
public async Task AddResource(ResourceDto resourceDto) { var resource = _mapper.Map <Resource>(resourceDto); resource.Guid = Guid.NewGuid(); resource.CreationDate = DateTime.Now; _resourceRepository.Add(resource); await _resourceRepository.SaveChangesAsync(); }