public async Task <IActionResult> CreateNewFoler(string id, string token, [FromBody] Folder folder)
        {
            try
            {
                var tokenManagerService = new TokenManagerService();
                if (tokenManagerService.ValidateToken(token, out userName, out hashKey))
                {
                    User user = await new UserService().GetUser(userName, hashKey);

                    var parentFolder = await new FolderService().GetFolder(id);

                    folder.FolderDate     = DateTime.Now;
                    folder.UserId         = parentFolder.UserId;
                    folder.ParentFolderId = id;

                    await new FolderService().CreateFolder(folder);
                    return(Ok());
                }

                return(Unauthorized());
            }
            catch
            {
                return(BadRequest());
            }
        }
        public async Task <IActionResult> GetItemsFromFolder(string id, string token)
        {
            try
            {
                var tokenManagerService = new TokenManagerService();
                if (tokenManagerService.ValidateToken(token, out userName, out hashKey))
                {
                    var user = await new UserService().GetUser(userName, hashKey);

                    var result = await access.GetAvailableItemsFromFolder(id, user.Id);

                    var parentFolder = await folderData.GetFolder(id);

                    var previusparent = new List <Object>()
                    {
                        new TimedModel()
                        {
                            PreviouseParent = parentFolder.ParentFolderId
                        }
                    };

                    return(Ok(result.Concat(previusparent)));
                }
                return(Unauthorized());
            }
            catch
            {
                return(BadRequest());
            }
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> AddBookData([FromForm] ResourceFileRequest bookDataRequest)
        {
            Stream stream = null;

            try
            {
                Request.Headers.TryGetValue("auth_key", out var authKey);
                if (bookDataRequest.JsonFile.Length > 0 && await _tokenManagerService.ValidateToken(authKey))
                {
                    stream = bookDataRequest.JsonFile.OpenReadStream();
                    using (var streamReader = new StreamReader(stream))
                    {
                        var fileContent = streamReader.ReadToEnd();
                        await _s3FileProcessorService.AddBookData(bookDataRequest.Name, fileContent);
                    }
                    return(StatusCode(StatusCodes.Status200OK, new { Status = "Data from the file successfully processed" }));
                }
                return(StatusCode(StatusCodes.Status500InternalServerError, new { Status = "Bad request" }));
            }
            catch (Exception exception)
            {
                _logger.LogError($"Error while processing data from the file: {exception.Message}");
                return(StatusCode(StatusCodes.Status500InternalServerError, new { Status = "Error while process data from the file", exception.Message }));
            }
            finally
            {
                if (stream != null)
                {
                    stream.Close();
                }
            }
        }
        public async Task <IActionResult> GetItems(string token)
        {
            try
            {
                var tokenManagerService = new TokenManagerService();
                if (tokenManagerService.ValidateToken(token, out userName, out hashKey))
                {
                    var user   = await new UserService().GetUser(userName, hashKey);
                    var result = await access.GetAvailableItems(user.Id);

                    return(Ok(result));
                }
                return(Unauthorized());
            }
            catch
            {
                return(BadRequest());
            }
        }
        public async Task <IActionResult> CreateNewNoteAccess(string id, string token, [FromBody] Object inputValue)
        {
            try
            {
                var tokenManagerService = new TokenManagerService();
                if (tokenManagerService.ValidateToken(token, out userName, out hashKey))
                {
                    var userEmail = JObject.Parse(inputValue.ToString()).Value <String>("UserEmail");
                    var role      = JObject.Parse(inputValue.ToString()).Value <String>("Role");
                    var user      = await new UserService().GetUserByEmail(userEmail);

                    await access.CreateNewNoteAccess(user.Id, id, role);

                    return(Ok());
                }

                return(Unauthorized());
            }
            catch
            {
                return(BadRequest());
            }
        }