public OperationResult <bool> SavePaper(IPaperDTO paperDTO) { try { IPaperDAC paperDAC = DACFactory.Create <IPaperDAC>(); IPaperDTO rnDTO = paperDAC.GetPaperByTitle(paperDTO.Name); if (paperDTO.PaperId == -1 && rnDTO != null) { return(OperationResult <bool> .CreateFailureResult(true, "Name can't be same to another Paper")); } else if (paperDTO.PaperId != -1 && rnDTO != null && rnDTO.PaperId != paperDTO.PaperId) { return(OperationResult <bool> .CreateFailureResult(true, "Name can't be same to another Paper")); } paperDAC.SavePaper(paperDTO); return(OperationResult <bool> .CreateSuccessResult(true, "Success")); } catch (Exception ex) { return(OperationResult <bool> .CreateErrorResult(false, ex.Message)); } }
public void SavePaper(IPaperDTO paperDTO) { var portalDb = new QuestionnaireEntities(); QuestionPaper paperE = null; if (paperDTO.PaperId == -1) { paperE = new QuestionPaper(); paperE.Name = paperDTO.Name; paperE.Description = paperDTO.Description; paperE.Duration = paperDTO.Duration; portalDb.QuestionPapers.Add(paperE); } else { paperE = portalDb.QuestionPapers.SingleOrDefault(n => n.Id == paperDTO.PaperId); paperE.Name = paperDTO.Name; paperE.Description = paperDTO.Description; paperE.Duration = paperDTO.Duration; } portalDb.SaveChanges(); paperDTO.PaperId = paperE.Id; }
public OperationResult <IPaperDTO> GetPaperById(int paperId) { try { IPaperDAC paperDAC = DACFactory.Create <IPaperDAC>(); IPaperDTO paperDTO = paperDAC.GetPaperById(paperId); return(OperationResult <IPaperDTO> .CreateSuccessResult(paperDTO, "Success")); } catch (Exception ex) { return(OperationResult <IPaperDTO> .CreateErrorResult(null, ex.Message)); } }
public IPaperDTO GetPaperById(int paperId) { IPaperDTO rv = DTOFactory.Create <IPaperDTO>(); var portalDb = new QuestionnaireEntities(); var paper = portalDb.QuestionPapers.SingleOrDefault(n => n.Id == paperId); rv.PaperId = paper.Id; rv.Name = paper.Name; rv.Description = paper.Description; rv.Duration = paper.Duration; rv.QuestionCount = paper.Questions.Count; return(rv); }
public ActionResult SavePaper(PaperVM paper) { if (ModelState.IsValid) { IPaperFacade paperFacade = FacadeFactory.Instance.Create <IPaperFacade>(); IPaperDTO paperDTO = DTOFactory.Instance.Create <IPaperDTO>(); paperDTO.PaperId = paper.PaperId; paperDTO.Name = paper.Name; paperDTO.Description = paper.Description; paperDTO.Duration = paper.Duration; //paperDTO.QuestionCount = paper.QuestionCount; var saveResult = paperFacade.SavePaper(paperDTO); if (saveResult.IsValid()) { return(new JsonResult() { JsonRequestBehavior = JsonRequestBehavior.AllowGet, Data = new { msg = "Saved", paperId = paperDTO.PaperId } }); } else { if (saveResult.HasFailed()) { ModelState.AddModelError("Name", saveResult.Message); return(PartialView("LoadPaperForm", paper)); } else { return(new RedirectResult("Error/")); } } } else { return(PartialView("LoadPaperForm", paper)); } }
public IList <IPaperDTO> GetAllPapers() { IList <IPaperDTO> rv = new List <IPaperDTO>(); var portalDb = new QuestionnaireEntities(); var papers = portalDb.QuestionPapers.ToList(); foreach (var paper in papers) { IPaperDTO paperDTO = DTOFactory.Create <IPaperDTO>(); paperDTO.PaperId = paper.Id; paperDTO.Name = paper.Name; paperDTO.Description = paper.Description; paperDTO.Duration = paper.Duration; paperDTO.QuestionCount = paper.Questions.Count; rv.Add(paperDTO); } return(rv); }
public IPaperDTO GetPaperByTitle(string title) { IPaperDTO rv = DTOFactory.Create <IPaperDTO>(); var portalDb = new QuestionnaireEntities(); var paper = portalDb.QuestionPapers.FirstOrDefault(n => n.Name.Equals(title)); if (paper != null) { rv.PaperId = paper.Id; rv.Name = paper.Name; rv.Description = paper.Description; rv.Duration = paper.Duration; rv.QuestionCount = paper.Questions.Count; } else { rv = null; } return(rv); }
public OperationResult <bool> SavePaper(IPaperDTO noticeDTO) { IPaperBDC paperBDC = BDCFactory.Create <IPaperBDC>(); return(paperBDC.SavePaper(noticeDTO)); }