/// <summary> /// Save Paper Entity /// </summary> /// <param name="item">Entity to save</param> /// <param name="errorMessage">Error Message</param> /// <returns>return true if save successfully, else return false</returns> public static bool Save(Paper item, out string errorMessage) { bool isValid = Validate(item, out errorMessage); if (isValid) { PaperDao.Save(item); } return isValid; }
/// <summary> /// Saves a Paper to the data store. /// </summary> /// <param name="item">The item to save</param> public static void Save(Paper item) { if (item.IsItemModified) { if (item.PaperId == null) { item.PaperId = Insert(item); } else { Update(item); } } }
/// <summary> /// Updates a Paper /// </summary> /// <param name="item">The Paper item to save</param> private static void Update(Paper item) { List<SqlParameter> parameters = new List<SqlParameter> { new SqlParameter("@PaperId", item.PaperId), new SqlParameter("@UserId", item.UserId), new SqlParameter("@PaperCategoryId", item.PaperCategory), new SqlParameter("@Name", item.Name), new SqlParameter("@Description", item.Description), new SqlParameter("@Author", item.Author) }; DataManager.ExecuteProcedure(ConferencePlusConnectionString, "Paper_Update", parameters); }
/// <summary> /// Inserts a new Paper /// </summary> /// <param name="item">The Paper item to insert</param> /// <returns>The id of the Paper item just inserted</returns> private static int Insert(Paper item) { List<SqlParameter> parameters = new List<SqlParameter> { new SqlParameter("@UserId", item.UserId), new SqlParameter("@PaperCategoryId", item.PaperCategory), new SqlParameter("@Name", item.Name), new SqlParameter("@Description", item.Description), new SqlParameter("@Author", item.Author) }; return Convert.ToInt32(DataManager.ExecuteScalarProcedure(ConferencePlusConnectionString, "Paper_Insert", parameters)); }
/// <summary> /// Validate Paper Entity /// </summary> /// <param name="item">Entity to validate</param> /// <param name="errorMessage">error message if vlidation failed</param> /// <returns>return true if entity passes validation logic, else return false</returns> public static bool Validate(Paper item, out string errorMessage) { StringBuilder builder = new StringBuilder(); if (item.Author.IsNullOrWhiteSpace()) { builder.AppendHtmlLine("*Author is required"); } if (item.Description.IsNullOrWhiteSpace()) { builder.AppendHtmlLine("*Description is required"); } if (item.Name.IsNullOrWhiteSpace()) { builder.AppendHtmlLine("*Name is required"); } if (item.PaperCategory == EnumPaperCategory.None) { builder.AppendHtmlLine("*Paper category is required"); } if (item.UserId == default(Guid)) { builder.AppendHtmlLine("*User is required"); } errorMessage = builder.ToString(); return errorMessage.IsNullOrWhiteSpace(); }
private void LoadControlFromPaper(Paper paper) { PaperName = paper.Name; PaperDescription = paper.Description; Category = paper.PaperCategory; Author = paper.Author; PaperId = paper.PaperId; }
private Paper GetPaperFromForm() { Paper paper = new Paper { Author = Author, Description = PaperDescription, IsItemModified = true, Name = PaperName, UserId = UserId, PaperId = ControlMode == EnumUserControlMode.Add ? null : PaperId, PaperCategory = Category }; return paper; }