Exemplo n.º 1
0
        public async Task <IActionResult> PostErrorAsync([FromRoute] Guid id, [FromForm] ErrorModel errorModel)
        {
            if (errorModel != null)
            {
                try
                {
                    if (_context.CurrentUser.Mid != errorModel.Mid)
                    {
                        var comment = errorModel.Comment.Trim();
                        var file    = errorModel.File;
                        if (id == Guid.Empty)
                        {
                            return(BadRequest(new Response {
                                IsSuccess = false, Message = "Invalid Id"
                            }));
                        }
                        if (file == null || !file.FileName.EndsWith(".zip"))
                        {
                            return(BadRequest(new Response {
                                IsSuccess = false, Message = "Invalid File"
                            }));
                        }
                        if (file.Length < 25)
                        {
                            bool isZipCheck = await _fileOperationsManager.IsZipFileEmpty(file);

                            if (isZipCheck)
                            {
                                Response responseInner = new Response();
                                responseInner.IsSuccess = false;
                                responseInner.Message   = "No Files found inside the Zip File.";
                                return(StatusCode(200, responseInner));
                            }
                        }
                        var response = await _requestManager.UploadErrorAsync(file, comment, id);

                        if (response.IsSuccess)
                        {
                            return(StatusCode(200, response));
                        }
                    }
                    return(Unauthorized());
                }
                catch (Exception)
                {
                    return(BadRequest(new Response {
                        IsSuccess = false, Message = "Error File Upload"
                    }));
                }
            }
            return(BadRequest(new Response {
                IsSuccess = false, Message = "Empty fields"
            }));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> PostAssignment(Guid id)
        {
            var response = new FileDownloadResponse();
            var file     = HttpContext.Request.Form.Files.FirstOrDefault();

            if (id == Guid.Empty)
            {
                return(BadRequest(new Response {
                    IsSuccess = false, Message = "Invalid Input Type"
                }));
            }
            if (file == null)
            {
                response.IsSuccess = false;
                response.Message   = "No File Found";
                return(StatusCode(200, response));
            }


            if (file.Length < 1024)
            {
                bool isZipCheck = await _fileOperationsManager.IsZipFileEmpty(file);

                if (isZipCheck)
                {
                    response.IsSuccess = false;
                    response.Message   = "No Files are found inside the Zip File.";
                    return(StatusCode(200, response));
                }
            }
            if (file.Length > 104857600)
            {
                response.IsSuccess = false;
                response.Message   = "File of the zip file is too large.";
                return(StatusCode(200, response));
            }
            if (file.FileName.EndsWith(".zip"))
            {
                response = await _courseManager.UpdateAssigmentAsync(id, file);

                if (response.IsSuccess)
                {
                    return(StatusCode(201, response));
                }
                else
                {
                    return(StatusCode(200, response));
                }
            }
            else
            {
                return(BadRequest(new Response {
                    IsSuccess = false, Message = "Invalid file Format"
                }));
            }
        }