public ActionResult Edit(int id = 0) { Posting post = db.Postings.Find(id); if (post == null) { post = new Posting(); } var postingViewModel = new PostingsViewModel { PostingType = "NORMAL" }; postingViewModel.postings = post; return View(postingViewModel); }
/* * METHOD : ToViewModel * DESCRIPTION : * Changes a posting type into a view model. Regardless of the posting * type, it can be made into a model. Once an posting is converted, * the view model is returned. * PARAMETERS : * this Posting posting : The posting to transform. * RETURNS : * postingViewModel : Depends on class; is an PostingViewModel. */ public static PostingsViewModel ToOfficialPostingViewModel(this Posting post) { BookstoreContext db = new BookstoreContext(); var PostingsViewModel = new PostingsViewModel(); PostingsViewModel.postings = (Posting)post; OfficialPosting offPost = (from ec in db.OfficialPostings where ec.PostingID == post.PostingID select ec).FirstOrDefault(); if (offPost != null) { PostingsViewModel.PostingType = "OFFICIAL"; } else { PostingsViewModel.PostingType = "NORMAL"; } // bookViewModel.ItemSeletList = BookController.GetDropDown(); //// add back the reasonForLeave drop-down PostingsViewModel.Opostings = (OfficialPosting)offPost; string tmpInstitutionName = ""; foreach (Institution x in db.Institutions) { if (post.Institution_ID == x.Institution_ID) { tmpInstitutionName = x.Name; break; } } PostingsViewModel.institution = tmpInstitutionName; return PostingsViewModel; }
public ActionResult EditOfficialBook(int id = 0) { Posting post = db.Postings.Find(id); if (post == null) { post = new Posting(); } OfficialPosting Opost = db.OfficialPostings.Find(id); if (Opost == null) { Opost = new OfficialPosting(); } var postingViewModel = new PostingsViewModel { PostingType = "OFFICIAL" }; postingViewModel.Opostings = Opost; postingViewModel.postings = post; return View(postingViewModel); }
public ActionResult EditOfficialBook(PostingsViewModel postingModel, int id = 0) { if (ModelState.IsValid) { string oldId = "", oldInfo =""; try { // find original Posting postingModel.Opostings.PostingID = id; var OriginalPost = db.OfficialPostings.Find(id); // UpdateExistingPosting(OriginalPost, postingModel.postings); oldId = OriginalPost.CourseID; oldInfo = OriginalPost.CourseInfo; OriginalPost.CourseID = postingModel.Opostings.CourseID; OriginalPost.CourseInfo = postingModel.Opostings.CourseInfo; db.Entry(OriginalPost).State = EntityState.Modified; db.SaveChanges(); } catch (DbEntityValidationException e) { //display all the validation error on the postingview model foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } } //Add Audit var userIds = WebSecurity.GetUserId(User.Identity.Name); var postId = id; AuditController.AuditEntry(userIds, postId, AuditController.MODIFYOFFICIAL,"COURSEID" ,oldId, postingModel.Opostings.CourseID); AuditController.AuditEntry(userIds, postId, AuditController.MODIFYOFFICIAL, "COURSEINFO", oldInfo, postingModel.Opostings.CourseInfo); return RedirectToAction("Index", "manage"); } return View(postingModel.postings.ToOfficialPostingViewModel()); }
public static PostingsViewModel ToPostingViewModel(this Posting post) { // conver db employee to employeeCompanyViewModel, uded in delete var PostingsViewModel = new PostingsViewModel(); PostingsViewModel.postings = (Posting)post; // bookViewModel.ItemSeletList = BookController.GetDropDown(); //// add back the reasonForLeave drop-down PostingsViewModel.PostingType = "NORMAL"; return PostingsViewModel; }
public ActionResult Edit(PostingsViewModel postingModel, int id = 0) { if (ModelState.IsValid) { try { // find original Posting postingModel.postings.PostingID = id; var OriginalPost = db.Postings.Find(id); var oldPost = new Posting // AUDIT { UserID = postingModel.postings.UserID, Posting_Date = postingModel.postings.Posting_Date, ExpiryDate = postingModel.postings.ExpiryDate, PostTitle = postingModel.postings.PostTitle, PostDescription = postingModel.postings.PostDescription, price = postingModel.postings.price, img = postingModel.postings.img, BookTitle = postingModel.postings.BookTitle, author = postingModel.postings.author, Institution_ID = postingModel.postings.Institution_ID, }; // UpdateExistingPosting(OriginalPost, postingModel.postings); OriginalPost.PostTitle = postingModel.postings.PostTitle; OriginalPost.PostDescription = postingModel.postings.PostDescription; OriginalPost.price = postingModel.postings.price; OriginalPost.img = postingModel.postings.img; OriginalPost.BookTitle = postingModel.postings.BookTitle; OriginalPost.author = postingModel.postings.author; db.Entry(OriginalPost).State = EntityState.Modified; db.SaveChanges(); //Add Audit var userIds = WebSecurity.GetUserId(User.Identity.Name); AuditController.AuditEntry(userIds, oldPost, OriginalPost); } catch (DbEntityValidationException e) { //display all the validation error on the postingview model foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } } return RedirectToAction("PostPreview2", "Post", postingModel.postings); } return View(postingModel.postings.ToPostingViewModel()); }
public ActionResult Index( PostingsViewModel postingModel) { if (ModelState.IsValid) { // Attempt to add a new post try { if (postingModel.ListName == null) { //Get infor for posting adn set it var userId = WebSecurity.GetUserId(User.Identity.Name); postingModel.postings.UserID = userId; postingModel.postings.Posting_Date = DateTime.Now; postingModel.postings.ExpiryDate = DateTime.Now.AddMonths(3); //get institution from email. postingModel.postings.Institution_ID = UserController.GetInstituion(User.Identity.Name); if (postingModel.filepath != null) { //var uploadDir = "~/uploads"; //var imagePath = Path.Combine(Server.MapPath(uploadDir), postingModel.filepath.FileName); //imageUrl = Path.Combine(uploadDir, postingModel.filepath.FileName); //postingModel.filepath.SaveAs(imagePath); //ViewBag.Logo = imageUrl; //postingModel.postings.img = imageUrl; } // int id = db.Postings.Add(postingModel.postings);//.PostingID; //if (User.IsInRole("admin")) //{ // if (postingModel.isOfficial) // { // postingModel.Opostings.PostingID = id; // db.OfficialPostings.Add(postingModel.Opostings); // } //} db.SaveChanges(); } } catch (DbEntityValidationException e) { //display all the validation error on the postingview model foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } } //Add Audit var userIds = WebSecurity.GetUserId(User.Identity.Name); var postId = postingModel.postings.PostingID; AuditController.AuditEntry(userIds, postId, AuditController.CREATE); return RedirectToAction("PostPreview", "Post", postingModel.postings); } return View(postingModel.postings.ToPostingViewModel()); }
public ActionResult Index(string ReturnUrl) { var postingViewModel = new PostingsViewModel { PostingType = "NORMAL" }; return View(postingViewModel); }