public ActionResult Create(Title model) { LoadLists(model); Validate(model); if (ModelState.IsValid) { Title saved = data.Insert(model, (Session["LoggedInUser"] as user).id); TempData["SuccessMessage"] = string.Format("\"{0}\" was created.", model.Name); return RedirectToAction("Edit", new { id = saved.Id }); } return View(model); }
public ActionResult Edit(Title model) { if (model.IsExporting) return ExportCsv(model); Validate(model); if (ModelState.IsValid) { data.Update(model, (Session["LoggedInUser"] as user).id); TempData["SuccessMessage"] = string.Format("\"{0}\" was updated.", model.Name); } var saved = data.GetById(model.Id); LoadLists(saved); return View(saved); }
public FileResult ExportCsv(Title model) { List<int> ids = model.ExportIds.Split(',').Select(int.Parse).ToList(); List<ContactCsvLine> items = data.GetCsv(ids); ContactController cntlr = new ContactController(); return cntlr.CreateCsv(items); }
public ActionResult Create() { var model = new Title { PubDate = DateTime.Now.Date }; LoadLists(model); return View(model); }
private void Validate(Title model) { if (model.Author < 1) { ModelState.AddModelError("Author", "Please select a valid Author from the auto complete choices"); ModelState.AddModelError(string.Empty, "Please fix the errors below."); } }
private void LoadLists(Title model) { var contactId = model.Author.ToString(); var contactName = string.IsNullOrEmpty(model.AuthorName) ? "Search for a Contact" : model.AuthorName; var contacts = new List<SelectListItem> { new SelectListItem { Text = contactName, Value = contactId } }; model.ContactSelects = new SelectList(contacts, "Value", "Text", null); }
public Title GetById(int id) { Dictionary<int, string> contactDictionary = new Dictionary<int, string>(); foreach (var c in dbContext.contacts.Select(x => new { Id = x.id, Name = x.firstname + " " + x.lastname }).ToList()) contactDictionary.Add(c.Id, c.Name); Title vm = new Title(); var title = dbContext.titles.FirstOrDefault(t => t.id == id); if (title == null) return null; vm = new Title { Id = title.id, Name = title.title1, Notes = title.notes, Author = title.author, Edition = title.edition, ISBN = title.isbn, PubDate = title.date_published, Subtitle = title.subtitle, AuthorName = title.author > 0 ? title.author_contact.firstname + " " + title.author_contact.lastname : string.Empty, Reviews = title.title_review.Select(r => new Review { Id = r.id, ReviewText = r.review_text != null && r.review_text.Length > 200 ? r.review_text.Substring(0, 200) + "..." : r.review_text, ReviewerId = r.reviewedby, ReviewerName = r.reviewedby > 0 ? r.review_contact.firstname + " " + r.review_contact.lastname : string.Empty, DateReviewed = r.date_reviewed, Venue = r.venue }).ToList(), Shipments = title.title_shipment.Select(s => new Shipment { Id = s.id, ContactId = s.contact_id, DateSent = s.date_sent, DateCreated = s.createdat, Quantity = s.quantity, Status = s.status, Type = s.type, ShouldFollowUp = s.should_followup, FollowUpText = s.should_followup ? "yes" : "no" }).ToList(), LastUpdated = string.Format("{0} at {1}", title.title_user.username, title.updatedat.ToShortDateString()) }; foreach (var s in vm.Shipments) { s.ContactName = contactDictionary[s.ContactId]; if (s.Status == "Pending" && s.Type == "Comp") vm.TotalCompPending += s.Quantity; if (s.Status == "Sent" && s.Type == "Comp") vm.TotalCompSent += s.Quantity; if (s.Status == "Pending" && s.Type == "Desk") vm.TotalDeskPending += s.Quantity; if (s.Status == "Sent" && s.Type == "Desk") vm.TotalDeskSent += s.Quantity; if (s.Status == "Pending" && s.Type == "Donation") vm.TotalDonationPending += s.Quantity; if (s.Status == "Sent" && s.Type == "Donation") vm.TotalDonationSent += s.Quantity; if (s.Status == "Pending" && s.Type == "Galleys") vm.TotalGalleyPending += s.Quantity; if (s.Status == "Sent" && s.Type == "Galleys") vm.TotalGalleySent += s.Quantity; if (s.Status == "Pending" && s.Type == "Review") vm.TotalReviewPending += s.Quantity; if (s.Status == "Sent" && s.Type == "Review") vm.TotalReviewSent += s.Quantity; if (s.Status == "Pending" && s.Type == "Award") vm.TotalAwardPending += s.Quantity; if (s.Status == "Sent" && s.Type == "Award") vm.TotalAwardSent += s.Quantity; } return vm; }
public void Update(Title title, int updatedby) { var existingTitle = dbContext.titles.First(t => t.id == title.Id); { existingTitle.isbn = title.ISBN; existingTitle.notes = title.Notes; existingTitle.subtitle = title.Subtitle; existingTitle.title1 = title.Name; existingTitle.edition = title.Edition; existingTitle.date_published = title.PubDate; existingTitle.author = title.Author; existingTitle.updatedat = DateTime.Now; existingTitle.updatedby = updatedby; dbContext.SaveChanges(); } }
public Title Insert(Title title, int createdBy) { title newTitle = new title { title1 = title.Name, author = title.Author, createdat = DateTime.Now, createdby = createdBy, updatedat = DateTime.Now, updatedby = createdBy, date_published = title.PubDate, edition = title.Edition, isbn = title.ISBN, notes = title.Notes, subtitle = title.Subtitle }; var t = dbContext.titles.Add(newTitle); var validationErrors = dbContext.GetValidationErrors().ToList(); string error = string.Empty; if (validationErrors.Count() > 0) error = "errors"; dbContext.SaveChanges(); title.Id = t.id; return title; }