public async Task <IActionResult> UploadDocs(int doctorId, int patientId, [FromForm] DocumentForCreateDto docForCreateDto) { if (doctorId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized("Пользователь не авторизован")); } var file = docForCreateDto.File; if (file == null || file.Length <= 0) { return(BadRequest("Не корретный документ.")); } var document = _mapper.Map <Document>(docForCreateDto); document.GetExtensionFromFullNameDocument(); if (await _documentService.SaveDocAsync(document, docForCreateDto.File)) { document.DocumentType = await _documentService.GetDocTypeAsync(document.Id); var documentForReturn = await _documentService.SetInterdepartId(document); return(Ok(documentForReturn)); } throw new Exception("Не предвиденная ошибка в ходе добавления документа, повторите снова."); }
public async Task <IActionResult> AddDocument(string userId, [FromForm] DocumentForCreateDto documentForCreateDto) { var uploadRes = await _uploadService.UploadFileToLocal( documentForCreateDto.File, userId, _env.WebRootPath, $"{Request.Scheme ?? ""}://{Request.Host.Value ?? ""}{Request.PathBase.Value ?? ""}", "Files\\Documents\\" + DateTime.Now.Year + "\\" + DateTime.Now.Month + "\\" + DateTime.Now.Day ); if (uploadRes.Status) { UserForDetailedDto userProfileDto = new UserForDetailedDto(); //return CreatedAtRoute("GetDocument", new { id = userId }, userProfileDto); //return CreatedAtRoute("GetDocument", new { version = "v1", controller = "Token", id = userId }, userProfileDto); //return CreatedAtAction("GetDocument", new { id = userId }, userProfileDto); return(CreatedAtAction(nameof(GetDocument), new { id = userId }, userProfileDto)); //return await GetDocument(userId); } return(BadRequest()); }
public async Task <IActionResult> AddDocument(string userId, [FromForm] DocumentForCreateDto documentForCreateDto) { var documentFromRepoApprove = await _db.DocumentRepository.GetAsync(p => p.Approve == 1 || p.Approve == 0); if (documentFromRepoApprove == null) { // var file = Request.Form.Files["file"]; var uploadRes = await _uploadService.UploadFileToLocal( documentForCreateDto.File, userId, _env.WebRootPath, $"{Request.Scheme ?? ""}://{Request.Host.Value ?? ""}{Request.PathBase.Value ?? ""}", "Files\\Documents\\" + DateTime.Now.Year + "\\" + DateTime.Now.Month + "\\" + DateTime.Now.Day ); if (uploadRes.Status) { var documentForCreate = new Document() { UserId = userId, Approve = 0, PicUrl = uploadRes.Url, Message = "بدون پیغام" }; var document = _mapper.Map(documentForCreateDto, documentForCreate); await _db.DocumentRepository.InsertAsync(document); if (await _db.SaveAsync()) { var documentForReturn = _mapper.Map <DocumentForReturnDto>(document); return(CreatedAtRoute("GetDocument", new { v = HttpContext.GetRequestedApiVersion().ToString(), id = document.Id, userId = userId }, documentForReturn)); } else { return(BadRequest("خطا در ثبت اطلاعات")); } } else { return(BadRequest(uploadRes.Message)); } } { if (documentFromRepoApprove.Approve == 1) { return(BadRequest("شما مدرک شناسایی تایید شده دارید و نمیتوانید دوباره آنرا ارسال کنید")); } else { return(BadRequest("مدارک ارسالی قبلیه شما در حال بررسی میباشد")); } } }