/// <summary> /// Attempts to create a model using incoming parameters. If parameters are valid, the model is created, otherwise /// null is returned, and error parameter describes what went wrong /// </summary> /// <param name="text"></param> /// <param name="Event"></param> /// <param name="user"></param> /// <param name="image"></param> /// <param name="imagePreview"></param> /// <param name="video"></param> /// <param name="videoThumbnail"></param> /// <param name="link"></param> /// <param name="CreatedByFullName"></param> /// <param name="LastUpdatedByFullName"></param> /// <param name="error"></param> /// <returns></returns> public static CommentModel CreateCommentModel(string text, int? Event, int? user, string image, string imagePreview, string video, string videoThumbnail, string link, string CreatedByFullName, string LastUpdatedByFullName, out string error) { error = null; //let's check parameters //copying logic from viewEvent.aspx.cs if (text.Contains("<script")) error = "text-attribute-invalid"; else if (!Event.HasValue) error = "event-attribute-required"; else if (!user.HasValue) error = "user-attribute-required"; if (!string.IsNullOrEmpty(error)) return null; CommentModel model = new CommentModel { created = DateTime.Now, updated = DateTime.Now, text = text, Event = Event.Value, user = user.Value, image = image, imagePreview = imagePreview, video = video, videoThumbnail = videoThumbnail, link= link, CreatedByFullName = CreatedByFullName, LastUpdatedByFullName = LastUpdatedByFullName }; return model; }
/// <summary> /// creates a businss object using a model /// </summary> /// <param name="model">a model with comment details</param> /// <returns>a business object for the comment</returns> public static Sedogo.BusinessObjects.SedogoEventComment CreateCommentBO(CommentModel model) { Sedogo.BusinessObjects.SedogoEventComment commentBO = new Sedogo.BusinessObjects.SedogoEventComment(model.CreatedByFullName); if(!string.IsNullOrEmpty(model.text)) commentBO.commentText = model.text; commentBO.eventID = model.Event; commentBO.postedByUserID = model.user; if(!string.IsNullOrEmpty(model.image) ) commentBO.eventImageFilename = model.image; if(!string.IsNullOrEmpty(model.imagePreview) ) commentBO.eventImagePreview = model.imagePreview; if(!string.IsNullOrEmpty(model.video)) commentBO.eventVideoFilename = model.video; if(!string.IsNullOrEmpty(model.videoThumbnail)) commentBO.eventVideoLink = model.videoThumbnail; if(!string.IsNullOrEmpty(model.link) ) commentBO.eventLink = model.link; return commentBO; }