public Question UpdateQuestion(Question questionData)
        {
            var question = _repo.GetById(questionData.Id);

            question.Title        = questionData.Title;
            question.Body         = questionData.Body;
            question.DateAnswered = questionData.DateAnswered;
            question.DateEdited   = DateTime.Now;
            var updatedQuestion = _repo.Edit(question);

            return(updatedQuestion);
        }
Esempio n. 2
0
        internal Question Edit(Question editQuestion, string creatorId)
        {
            Question data = _repo.GetById(editQuestion.Id);

            if (data == null)
            {
                throw new Exception("Invalid Id");
            }
            if (data.CreatorId != creatorId)
            {
                throw new Exception("Denied Invalid Permissions");
            }
            if (data.IsSolved == true)
            {
                throw new Exception("Question has Been Solved");
            }
            editQuestion.CreatorId   = creatorId;
            editQuestion.Title       = editQuestion.Title == null ? data.Title : editQuestion.Title;
            editQuestion.Description = editQuestion.Description == null ? data.Description : editQuestion.Description;
            editQuestion.DateCreated = data.DateCreated;
            editQuestion.DateClosed  = editQuestion.DateClosed == null ? data.DateClosed : editQuestion.DateClosed;
            editQuestion.DateUpdated = editQuestion.DateUpdated == null ? data.DateUpdated : editQuestion.DateUpdated;
            return(_repo.Edit(editQuestion));
        }