public Post SubmitPost(CreatePostModel model) { //If statement to update the post if there is already one in the database. if (model.PostId != 0) { //converts the data into a post object. Post newPost = ConvertToPostWithPostId(model.PostPurpose, model.PostTitle, model.PostDescription, model.ExpirationDate, model.PostStatus, model.SubCategoryId, model.DatePosted, model.CategoryId, model.PostedBy, model.PostId); //command to update the post. UpdatePostCommand command = new UpdatePostCommand(newPost); commandBus.Execute(command); //grabs all images that were uploaded. List <String> updateImagePaths = ImagePathCreation(); //inserts each image into the picture database. foreach (string path in updateImagePaths) { InsertPictureCommand pictureCommand = new InsertPictureCommand(new Picture(newPost.PostId, path)); commandBus.Execute(pictureCommand); } return(newPost); } //converts the data into a post object. Post post = ConvertToPost(model.PostPurpose, model.PostTitle, model.PostDescription, model.ExpirationDate, model.PostStatus, model.SubCategoryId, model.DatePosted, model.CategoryId, model.PostedBy); InsertPostCommand postcommand = new InsertPostCommand(post); commandBus.Execute(postcommand, delegate(Post result) { post = result; }); // grabs all images that were uploaded. List <String> imagePaths = ImagePathCreation(); //inserts each image into the picture database. foreach (string path in imagePaths) { InsertPictureCommand command = new InsertPictureCommand(new Picture(post.PostId, path)); commandBus.Execute(command); } return(post); }
/// <summary> /// Handler for the InsertPictureCommand command /// </summary> /// <param name="command">the InsertPicture Command</param> public void HandleCommand(InsertPictureCommand command) { postRepository.InsertPicture(command.Picture); }
public Event SaveEvent() { string category = Request.Form.Get("Event.CategoryId.Id"); string eventVenue = Request.Form.Get("Event.Venue"); string eventName = Request.Form.Get("Event.EventName"); string eventDate = Request.Form.Get("Event.EventDate"); string ticketQuantity = Request.Form.Get("Event.Quantity"); string maxClaims = Request.Form.Get("Event.Claims"); string eventDescription = Request.Form.Get("Event.EventDescription"); string eventId = Request.Form.Get("Event.EventId"); DateTime enteredDate = DateTime.Parse(eventDate); DateTime datePosted = DateTime.Now; int enteredTicketQuantity = int.Parse(ticketQuantity); int categoryId = int.Parse(category); int enteredMaxClaims = int.Parse(maxClaims); int postStatus = 1; int totalHandsRaised = 0; int maxWinners = Convert.ToInt32(Math.Floor(Convert.ToDecimal((enteredTicketQuantity / enteredMaxClaims)))); int remainingWinners = maxWinners; if (eventId != "") { int updateEventId = int.Parse(eventId); Event updateEvent = ConvertToEvent(eventVenue, eventName, enteredDate, enteredTicketQuantity, enteredMaxClaims, categoryId, datePosted, postStatus, eventDescription, totalHandsRaised, maxWinners, remainingWinners); updateEvent.EventId = updateEventId; UpdateEventCommand updateCommand = new UpdateEventCommand(updateEvent); commandBus.Execute(updateCommand); List <String> updateImagePaths = ImagePathCreation(); foreach (string path in updateImagePaths) { InsertPictureCommand eventCommand = new InsertPictureCommand(new Picture(0, path, updateEvent.EventId)); commandBus.Execute(eventCommand); } return(updateEvent); } Event newEvent = ConvertToEvent(eventVenue, eventName, enteredDate, enteredTicketQuantity, enteredMaxClaims, categoryId, datePosted, postStatus, eventDescription, totalHandsRaised, maxWinners, remainingWinners); InsertEventCommand command = new InsertEventCommand(newEvent); commandBus.Execute(command, delegate(Event result) { newEvent = result; }); List <String> imagePaths = ImagePathCreation(); foreach (string path in imagePaths) { InsertPictureCommand eventCommand = new InsertPictureCommand(new Picture(0, path, newEvent.EventId)); commandBus.Execute(eventCommand); } return(newEvent); }