/// <summary> /// Guarda los cambios del recurso existente. /// </summary> /// <param name="map"></param> /// <returns></returns> public bool Edit(Poll poll) { PollAnswerManager pollAnswerManager = new PollAnswerManager(); PollQuestionManager pollQuestionManager = new PollQuestionManager(); PollMapper pollMapper = new PollMapper(); if (!IsValideForEdit(poll)) return false; //Si fue respondida, no es posible la edición. //Notar que a menos que se editen las preguntas, Questions estará vacío bool hasQuestions = poll.Questions != null && poll.Questions.Count > 0; if (hasQuestions && pollAnswerManager.HasAnswers(poll)) { string errorDescription = "La encuesta no puede ser editada porque al menos una persona contestó."; log.AddLogInfo("Edit", errorDescription, this); AddError(new ResultBE(ResultBE.Type.FAIL, errorDescription)); return false; } if (!pollMapper.Edit(poll)) { string errorDescription = "No se ha podido modificar la encuesta."; log.AddLogCritical("Edit", errorDescription, this); AddError(new ResultBE(ResultBE.Type.FAIL, errorDescription)); return false; } if (hasQuestions && !pollQuestionManager.Edit(poll)) { AddError(pollQuestionManager.Errors); return false; } return true; }
/// <summary> /// Recupera la encuesta de satisfacción (activa) /// </summary> /// <returns></returns> public Poll GetSatisfactionPoll() { PollQuestionManager pollQuestionManager = new PollQuestionManager(); PollMapper pollMapper = new PollMapper(); Poll poll = pollMapper.GetSatisfactionPoll(); PopulatePoll(poll); return poll; }
/// <summary> /// Recupera una encuesta en base a su id. /// </summary> /// <param name="id"></param> /// <returns></returns> public Poll Get(int id) { PollQuestionManager pollQuestionManager = new PollQuestionManager(); PollMapper pollMapper = new PollMapper(); Poll poll = pollMapper.Get(id); PopulatePoll(poll); return poll; }
/// <summary> /// Completa con elementos adicionales la encuesta /// </summary> /// <param name="poll"></param> /// <returns></returns> private void PopulatePoll(Poll poll) { // Como es válida la no existencia, simplemente retorno un null if (poll == null) return; PollQuestionManager pollQuestionManager = new PollQuestionManager(); List<PollQuestion> pollQuestions = pollQuestionManager.Get(poll.Id); if (pollQuestions == null || pollQuestions.Count == 0) { AddError(pollQuestionManager.Errors); return; } poll.Questions = pollQuestions; }
/// <summary> /// Persiste el elemento. /// </summary> /// <param name="Poll"></param> /// <returns></returns> public bool Save(Poll poll) { if (!IsValid(poll)) return false; PollMapper pollMapper = new PollMapper(); PollQuestionManager pollQuestionManager = new PollQuestionManager(); if (!pollMapper.Save(poll)) { string errorDescription = "No se ha podido guardar la encuesta."; log.AddLogCritical("Save", errorDescription, this); AddError(new ResultBE(ResultBE.Type.FAIL, errorDescription)); return false; } if (!pollQuestionManager.Save(poll)) { AddError(pollQuestionManager.Errors); return false; } return true; }