コード例 #1
0
ファイル: AppointmentBl.cs プロジェクト: andreyu/Reports
 public bool SaveComment(SaveCommentModel model,RequestTypeEnum type)
 {
     try
     {
         User user = UserDao.Load(AuthenticationService.CurrentUser.Id);
         switch (type)
         {
             case RequestTypeEnum.Appointment:
                 Appointment entity = AppointmentDao.Load(model.DocumentId);
                 AppointmentComment comment = new AppointmentComment
                                                  {
                                                      Comment = model.Comment,
                                                      Appointment = entity,
                                                      DateCreated = DateTime.Now,
                                                      User = user,
                                                  };
                 AppointmentCommentDao.MergeAndFlush(comment);
                 break;
             case RequestTypeEnum.AppointmentReport:
                 AppointmentReport rep = AppointmentReportDao.Load(model.DocumentId);
                 AppointmentReportComment comm = new AppointmentReportComment
                 {
                     Comment = model.Comment,
                     AppointmentReport = rep,
                     DateCreated = DateTime.Now,
                     User = user,
                 };
                 AppointmentReportCommentDao.MergeAndFlush(comm);
                 break;
             default:
                 throw new ValidationException(string.Format(StrInvalidCommentType,(int)type));
         }
         return true;
     }
     catch (Exception ex)
     {
         AppointmentCommentDao.RollbackTran();
         Log.Error("Exception", ex);
         model.Error = StrException + ex.GetBaseException().Message;
         return false;
     }
 }
コード例 #2
0
ファイル: EmployeeController.cs プロジェクト: andreyu/Reports
 public ContentResult SaveComment(int documentId, string comment)
 {
     bool saveResult = false;
     string error;
     try
     {
         if (comment == null || string.IsNullOrEmpty(comment.Trim()))
         {
             error = "Комментарий - обязательное поле";
         }
         else if(comment.Trim().Length > MaxCommentLength)
         {
             error = string.Format("Длина поля 'Комментарий' не может превышать {0} символов.",MaxCommentLength);
         }
         else
         {
             var model = new SaveCommentModel
                             {
                                 DocumentId = documentId,
                                 Comment = comment.Trim(),
                             };
             saveResult = EmployeeBl.SaveComment(model);
             error = model.Error;
         }
     }
     catch (Exception ex)
     {
         Log.Error("Exception on SaveComment:", ex);
         error = ex.GetBaseException().Message;
         saveResult = false;
     }
     JavaScriptSerializer jsonSerializer = new JavaScriptSerializer();
     var jsonString = jsonSerializer.Serialize(new SaveTypeResult { Error = error, Result = saveResult });
     return Content(jsonString);
 }
コード例 #3
0
ファイル: HomeController.cs プロジェクト: andreyu/Reports
 public ContentResult SaveComment(int id, int typeId, string comment)
 {
     bool saveResult = false;
     string error;
     try
     {
         if (comment == null || string.IsNullOrEmpty(comment.Trim()))
         {
             error = StrCommentIsRequired;
         }
         else if (comment.Trim().Length > MaxCommentLength)
         {
             error = string.Format(StrCommentLengthError, MaxCommentLength);
         }
         else
         {
             var model = new SaveCommentModel
             {
                 DocumentId = id,
                 TypeId = typeId,
                 Comment = comment.Trim(),
             };
             //saveResult = RequestBl.SaveComment(model);
             switch (typeId)
             {
                 case (int)RequestTypeEnum.Appointment:
                     saveResult = AppointmentBl.SaveComment(model, RequestTypeEnum.Appointment);
                     break;
                 case (int)RequestTypeEnum.AppointmentReport:
                     saveResult = AppointmentBl.SaveComment(model, RequestTypeEnum.AppointmentReport);
                     break;
                 case (int)RequestTypeEnum.HelpServiceRequest:
                     saveResult = HelpBl.SaveComment(model, RequestTypeEnum.HelpServiceRequest);
                     break;
                 default:
                     throw new ArgumentException(string.Format(StrInvalidCommentType, typeId));
             }
             error = model.Error;
         }
     }
     catch (Exception ex)
     {
         Log.Error("Exception on SaveComment:", ex);
         error = ex.GetBaseException().Message;
         saveResult = false;
     }
     JavaScriptSerializer jsonSerializer = new JavaScriptSerializer();
     var jsonString = jsonSerializer.Serialize(new SaveTypeResult { Error = error, Result = saveResult });
     return Content(jsonString);
 }
コード例 #4
0
ファイル: EmployeeBl.cs プロジェクト: andreyu/Reports
 public bool SaveComment(SaveCommentModel model)
 {
     try
     {
         int userId = AuthenticationService.CurrentUser.Id;
         Document doc = documentDao.Load(model.DocumentId);
         User user = UserDao.Load(userId);
         DocumentComment comment = new DocumentComment
                                       {
                                          Comment = model.Comment,
                                          Document = doc,
                                          DateCreated = DateTime.Now,
                                          User = user,
                                       };
         DocumentCommentDao.MergeAndFlush(comment);
         //doc.Comments.Add(comment);
         //DocumentDao.MergeAndFlush(doc);
         return true;
     }
     catch (Exception ex)
     {
         Log.Error("Exception", ex);
         model.Error = "Исключение: " + ex.GetBaseException().Message;
         return false;
     }
 }