public virtual ActionResult UploadAttachment(AttachmentModel attachmentModel, HttpPostedFileBase fileAttach) { try { if (fileAttach == null) { return(Json(new { isError = true, Message = @"ورودی نامعتبر!" })); } attachmentModel.Extention = Path.GetExtension(fileAttach.FileName); attachmentModel.Size = fileAttach.ContentLength; if (!ModelState.IsValid) { return(Json(new { isError = true, Message = @"ورودی نامعتبر!" })); } using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { var addressUrlFile = new AddressUrlFile(Server.MapPath("~//")); var path = addressUrlFile.UploadFiles; Useful.CreateFolderIfNeeded(addressUrlFile.UploadFiles); path += Guid.NewGuid() + Path.GetExtension(fileAttach.FileName); fileAttach.SaveAs(path); attachmentModel.File = Path.GetFileName(path); var data = _attachmentService.Add(attachmentModel); scope.Complete(); return(Json(new { isError = !data.Item1, Message = data.Item2 })); } } catch (Exception) { return(Json(new { isError = true, Message = @"خطا در ویرایش اطلاعات پرسنلی" })); } }
public IActionResult Save([FromBody] UploadFileVM uploadFileVM) { try { var curUser = accountUtil.GetCurrentUser(User); Attachment attachment = uploadFileVM.ToModel(); AttachmentService.Add(attachment, curUser.ID); if (uploadFileVM.ModelID.HasValue && uploadFileVM.ModelID.Value > 0) { AttachFile(attachment, uploadFileVM.ModelID.Value, uploadFileVM.FileType, curUser.ID); } return(Ok(new { id = attachment.ID })); } catch (Exception ex) { return(CustomBadRequest(ex)); } }
public IActionResult Save([FromBody] UploadFileVM uploadFileVM) { try { var curUser = accountUtil.GetCurrentUser(User); Attachment attachment = uploadFileVM.ToModel(); AttachmentService.Add(attachment, curUser.ID); if (uploadFileVM.model_id.HasValue && uploadFileVM.model_id.Value > 0) { AttachFile(attachment, uploadFileVM.model_id.Value, uploadFileVM.file_type, curUser.ID); } return(Ok(new { id = attachment.ID })); } catch (Exception ex) { TelegramBotService.SendMessage(ex.Message, origin); return(CustomBadRequest(ex)); } }
public Task <IResultModel> Upload(IFormFile formFile) { return(_service.Add(null)); }
public Task <IResultModel> Add(AttachmentAddModel model) { return(_service.Add(model)); }