public async Task <FileModel> Edit(Guid id, FileModelBMO model) { if (model.ParentFolderId != null) { // check if parent is folder or not var parent = await _db.Files.SingleOrDefaultAsync(x => x.Id == model.ParentFolderId); if (parent.IsFolder == false) { throw new Exception("Parent must be folder!"); } } var file = await GetEntities().SingleOrDefaultAsync(x => x.Id == id); if (file == null) { throw new Exception("File/folder does not exists!"); } file.Name = model.Name; file.ParentFolderId = model.ParentFolderId; file.LastModifiedDate = DateTime.UtcNow; await _db.SaveChangesAsync(); return(file); }
public async Task <FileModel> Create(FileModelBMO model) { if (model.ParentFolderId != null) { // check if parent is folder or not var parent = await _db.Files.SingleOrDefaultAsync(x => x.Id == model.ParentFolderId); if (parent.IsFolder == false) { throw new Exception("Parent must be folder!"); } } var newFile = new FileModel { IsFolder = model.IsFolder, Name = model.Name, LastModifiedDate = DateTime.UtcNow, ParentFolderId = model.ParentFolderId }; _db.Files.Add(newFile); await _db.SaveChangesAsync(); return(await GetEntities().SingleOrDefaultAsync(x => x.Id == newFile.Id)); }
public async Task <FileModel> Edit(Guid id, [FromBody] FileModelBMO model) { var result = await _service.Edit(id, model); return(result); }
public async Task <FileModel> Create([FromBody] FileModelBMO model) { var result = await _service.Create(model); return(result); }