public HttpResponseMessage SubmitTest(pdfResult pdfresult) { try { CMSResult cmsResult = new CMSResult(); var pdf = JsonConvert.SerializeObject(pdfresult.PDFCategoryId); var result = _pdfuploadservice.Save(new PDFUpload { PDFCategoryId = pdfresult.PDFCategoryId, FileName = pdfresult.Name, Title = pdfresult.PDFCategoryName }); return(Request.CreateResponse(HttpStatusCode.OK, "OK")); } catch (Exception ex) { _logger.Warn(ex.Message); return(Request.CreateResponse(HttpStatusCode.OK, "Error")); } }
public ActionResult Create(PDFUploadViewModel viewModel) { var cmsResult = new CMSResult(); if (ModelState.IsValid) { if (viewModel.FilePath.ContentLength == 0) { cmsResult.Results.Add(new Result { Message = "Pdf is required", IsSuccessful = false }); } if (!Common.Constants.PdfType.Contains(viewModel.FilePath.ContentType)) { cmsResult.Results.Add(new Result { Message = "Please choose pdf file.", IsSuccessful = false }); _logger.Warn(cmsResult.Results.FirstOrDefault().Message); Warning(cmsResult.Results.FirstOrDefault().Message, true); } if (cmsResult.Success) { var pdfupload = new PDFUpload { ClassId = viewModel.ClassId, Title = viewModel.Title, FileName = viewModel.FilePath.FileName, IsVisible = viewModel.IsVisible, PDFCategoryId = viewModel.PDFCategoryId, IsSend = viewModel.IsSend }; var result = _pdfUploadService.Save(pdfupload); var pdfuploadId = pdfupload.PDFUploadId; if (result.Success) { string folderPath = Server.MapPath(string.Concat("~/PDF/", Common.Constants.PdfFileFolder)); if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } var pathToSaveQI = Path.Combine(folderPath, string.Format("{0}", viewModel.FilePath.FileName)); if (viewModel.FilePath != null) { viewModel.FilePath.SaveAs(pathToSaveQI); } var bodySubject = "Web portal - PDF Upload Created"; var message = "PDFUpload Created Successfully"; SendMailToAdmin(message, viewModel.Title, viewModel.PDFCategoryName, viewModel.ClassName, bodySubject); var successMessage = result.Results.FirstOrDefault().Message; CMSResult sendNotificationResult = new CMSResult(); if (viewModel.IsSend) { sendNotificationResult = SendNotification(viewModel.ClassId, viewModel.Title, viewModel.FilePath.FileName, viewModel.PDFCategoryName, pdfuploadId); successMessage += " <br/>" + sendNotificationResult.Results.FirstOrDefault().Message; } Success(successMessage); ModelState.Clear(); viewModel = new PDFUploadViewModel(); } else { _logger.Warn(result.Results.FirstOrDefault().Message); Warning(result.Results.FirstOrDefault().Message, true); } } } else { cmsResult.Results.Add(new Result { Message = "Please select PDF!", IsSuccessful = true }); } var classes = _classService.GetClasses().ToList(); var pdfcategories = _pdfCategoryService.GetPDFCategories().ToList(); viewModel.Classes = new SelectList(classes, "ClassId", "Name"); viewModel.PDFCategories = new SelectList(pdfcategories, "PDFCategoryId", "Name"); return(View(viewModel)); }