Beispiel #1
0
        public ContentResult SaveQuestion(/*int id, string question, string answer*/HelpSaveFaqModel model)
        {
            bool saveResult = false;
            string error = string.Empty;
            try
            {
                if (string.IsNullOrEmpty(model.Question.Trim()))
                    error = StrQuestionIsRequired;
                else if (model.Question.Trim().Length > MaxQuestionLength)
                    error = string.Format(StrQuestionLengthError, MaxQuestionLength);

                if (string.IsNullOrEmpty(model.Answer.Trim()))
                    error = StrAnswerIsRequired;
                else if (model.Answer.Trim().Length > MaxAnswerLength)
                    error = string.Format(StrAnswerLengthError, MaxAnswerLength);

                if (string.IsNullOrEmpty(error))
                {
                    saveResult = HelpBl.SaveFaq(model);
                    if (!saveResult)
                        error = model.Error;
                }
            }
            catch (Exception ex)
            {
                Log.Error("Exception on SaveQuestion:", ex);
                error = ex.GetBaseException().Message;
                saveResult = false;
            }
            JavaScriptSerializer jsonSerializer = new JavaScriptSerializer();
            var jsonString = jsonSerializer.Serialize(new SaveTypeResult { Error = error, Result = saveResult });
            return Content(jsonString);
        }
Beispiel #2
0
 public bool SaveFaq(HelpSaveFaqModel model)
 {
     try
     {
         if (AuthenticationService.CurrentUser.UserRole != UserRole.Admin)
         {
             model.Error = StrCannotEditFaq;
             return false;
         }
         User user = UserDao.Load(AuthenticationService.CurrentUser.Id);
         HelpFaq entity = new HelpFaq();
         if (model.Id > 0)
             entity = HelpFaqDao.Load(model.Id);
         entity.Question = model.Question;
         entity.Answer = model.Answer;
         entity.DateCreated = DateTime.Now;
         entity.User = user;
         HelpFaqDao.SaveAndFlush(entity);
         return true;
     }
     catch (Exception ex)
     {
         helpFaqDao.RollbackTran();
         Log.Error("Exception", ex);
         model.Error = StrException + ex.GetBaseException().Message;
         return false;
     }
 }