public CMSResult Update(DailyPracticePaper oldPaper) { CMSResult result = new CMSResult(); var isExists = _repository.Project <DailyPracticePaper, bool>(papers => (from paper in papers where paper.DailyPracticePaperId != oldPaper.DailyPracticePaperId && paper.Description == oldPaper.Description select paper).Any()); if (isExists) { result.Results.Add(new Result { IsSuccessful = false, Message = string.Format("Practice paper already exists!", "") }); } else { var paper = _repository.Load <DailyPracticePaper>(x => x.DailyPracticePaperId == oldPaper.DailyPracticePaperId); paper.Description = oldPaper.Description; paper.AttachmentDescription = oldPaper.AttachmentDescription; paper.DailyPracticePaperDate = oldPaper.DailyPracticePaperDate; paper.FileName = oldPaper.FileName; _repository.Update(paper); result.Results.Add(new Result { IsSuccessful = true, Message = string.Format("Time table successfully updated!", "") }); } return(result); }
public CMSResult Save(DailyPracticePaper dailyPracticePaper) { CMSResult result = new CMSResult(); var isExists = _repository.Project <DailyPracticePaper, bool>(dailyPracticePapers => ( from p in dailyPracticePapers where p.Description == dailyPracticePaper.Description select p ).Any()); if (isExists) { result.Results.Add(new Result { IsSuccessful = false, Message = string.Format("PDF file '{0}' already exists!", dailyPracticePaper.Description) }); } else { _repository.Add(dailyPracticePaper); _repository.CommitChanges(); result.Results.Add(new Result { IsSuccessful = true, Message = string.Format("Daily Practice Paper added successfully!") }); } return(result); }
public ActionResult Create(DailyPracticePaperViewModel viewModel) { var cmsResult = new CMSResult(); var roleUserId = User.Identity.GetUserId(); var roles = _aspNetRolesService.GetCurrentUserRole(roleUserId); if (ModelState.IsValid) { string fileName = ""; Guid guid = Guid.NewGuid(); if (viewModel.FilePath != null) { if (viewModel.AttachmentDescription == null) { _logger.Warn("Please enter attachment description."); Warning("Please enter attachment description.", true); ReturnViewModel(viewModel, roles, roleUserId); return(View(viewModel)); } else if (Common.Constants.ImageTypes.Contains(viewModel.FilePath.ContentType) || Common.Constants.PdfType.Contains(viewModel.FilePath.ContentType)) { if (viewModel.FilePath != null) { if (viewModel.FilePath != null) { if (Common.Constants.ImageTypes.Contains(viewModel.FilePath.ContentType)) { fileName = string.Format("{0}.jpg", guid); } else { fileName = string.Format("{0}.pdf", guid); } } } } else { _logger.Warn("Please choose either a JPEG, JPG, PNG image or pdf file."); Warning("Please choose either a JPEG, JPG, PNG image or pdf file", true); ReturnViewModel(viewModel, roles, roleUserId); return(View(viewModel)); } } var description = viewModel.Description.Replace("\r\n", "<br />"); viewModel.Description = description; var dailyPracticePaper = new DailyPracticePaper { Description = viewModel.Description, SelectedBranches = viewModel.SelectedBranches != null ? viewModel.SelectedBranches : "", SelectedClasses = viewModel.SelectedClasses != null ? viewModel.SelectedClasses : "", SelectedBatches = viewModel.SelectedBatches != null ? viewModel.SelectedBatches : "", FileName = fileName, AttachmentDescription = viewModel.AttachmentDescription != null ? viewModel.AttachmentDescription : "", DailyPracticePaperDate = viewModel.DailyPracticePaperDate }; var result = _dailyPracticePaperService.Save(dailyPracticePaper); if (result.Success) { var dailyPracticePaperId = dailyPracticePaper.DailyPracticePaperId; if (viewModel.FilePath != null) { var pathToSaveQI = ""; string folderPath = Server.MapPath(string.Concat("~/PDF/", Common.Constants.DailyPracticePaperFile)); if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } if (Common.Constants.ImageTypes.Contains(viewModel.FilePath.ContentType)) { pathToSaveQI = Path.Combine(folderPath, string.Format("{0}.jpg", guid)); } else { pathToSaveQI = Path.Combine(folderPath, string.Format("{0}.pdf", guid)); } if (viewModel.FilePath != null) { viewModel.FilePath.SaveAs(pathToSaveQI); } } var sendAppNotification = SendAppNotification(viewModel, dailyPracticePaperId); if (roles == "BranchAdmin") { SendDailyPracticePaper(viewModel); } Success(result.Results.FirstOrDefault().Message + "<br />" + sendAppNotification.Results[0].Message); ModelState.Clear(); viewModel = new DailyPracticePaperViewModel(); } else { _logger.Warn(result.Results.FirstOrDefault().Message); Warning(result.Results.FirstOrDefault().Message, true); } } ReturnViewModel(viewModel, roles, roleUserId); return(View(viewModel)); }