public ActionResult AddDocument(DocumentModel model) { if (ModelState.IsValid) { var userinfo = UserManager.Users.FirstOrDefault(x => x.user_info_id == model.PatientID).UserInfo; var folderName = userinfo.last_name + userinfo.first_name; folderName = normalize(folderName); folderName.ToLower(); var result = UploadDocumentFile(model.DocumentFile, folderName); if (result) { var doc = new MedicalDocument { description = model.Description, url = Url.Content("/MedicalDocuments/" + folderName + '/' + model.DocumentFile.FileName), upload_date = DateTime.Today, patient_id = model.PatientID }; _IMedicalDocumentsRepository.CreateMedicalDocument(doc); TempData["Success"] = "Pomyślnie dodano dokument"; } } else { TempData["Warning"] = "Dokument musi mieć rozszerzenie .doc, .docx, .pdf, .jpg, .jpeg lub .png i rozmiar niewiększy niż 3MB."; } return(RedirectToAction("MedicalDocumentation")); }
public void CreateMedicalDocument(MedicalDocument doc) { if (doc != null) { _context.Entry(doc).State = EntityState.Added; _context.Documents.Add(doc); _context.SaveChanges(); } }