Esempio n. 1
0
        public ContentResult SaveVersion(HelpSaveVersionModelFromView vModel)
        {
            bool saveResult = false;
            string error = string.Empty;
            DateTime dtReleaseDate = DateTime.Today;
            try
            {
                if (string.IsNullOrEmpty(vModel.Comment.Trim()))
                    error = StrCommentIsRequired;
                else if (vModel.Comment.Trim().Length > MaxVersionLength)
                    error = string.Format(StrCommentLengthError, MaxCommentLength);

                if (string.IsNullOrEmpty(vModel.ReleaseDate.Trim()))
                    error = StrReleaseDateIsRequired;
                else if (!DateTime.TryParse(vModel.ReleaseDate, out dtReleaseDate))
                    error = StrReleaseDateIsInvalid;
                if(string.IsNullOrEmpty(error))
                {
                    HelpSaveVersionModel model = new HelpSaveVersionModel
                                                     {
                                                         Comment = vModel.Comment.Trim(),
                                                         Id = vModel.Id,
                                                         ReleaseDate = dtReleaseDate,
                                                     };
                    saveResult = HelpBl.SaveVersion(model);
                    if (!saveResult)
                        error = model.Error;
                }
            }
            catch (Exception ex)
            {
                Log.Error("Exception on SaveVersion:", ex);
                error = ex.GetBaseException().Message;
                saveResult = false;
            }
            JavaScriptSerializer jsonSerializer = new JavaScriptSerializer();
            var jsonString = jsonSerializer.Serialize(new SaveTypeResult { Error = error, Result = saveResult });
            return Content(jsonString);
        }
Esempio n. 2
0
 public bool SaveVersion(HelpSaveVersionModel model)
 {
     try
     {
         if (AuthenticationService.CurrentUser.UserRole != UserRole.Admin)
         {
             model.Error = StrCannotEditVersion;
             return false;
         }
         User user = UserDao.Load(AuthenticationService.CurrentUser.Id);
         HelpVersion entity = new HelpVersion();
         if(model.Id > 0)
             entity = HelpVersionDao.Load(model.Id);
         entity.Comment = model.Comment;
         entity.DateCreated = DateTime.Now;
         entity.User = user;
         entity.ReleaseDate = model.ReleaseDate;
         HelpVersionDao.SaveAndFlush(entity);
         return true;
     }
     catch (Exception ex)
     {
         helpVersionDao.RollbackTran();
         Log.Error("Exception", ex);
         model.Error = StrException + ex.GetBaseException().Message;
         return false;
     }
 }