コード例 #1
0
 public ActionResult Create()
 {
     var model = new Review();
     ParseQueryString(Request, model, true);
     LoadLists(model);
     return View(model);
 }
コード例 #2
0
        public ActionResult Edit(Review model)
        {
            LoadLists(model);
            Validate(model);

            if (ModelState.IsValid)
            {
                data.Update(model, (Session["LoggedInUser"] as user).id);
                TempData["SuccessMessage"] = string.Format("Review was updated.");

                if (model.Redirect == "title")
                    return RedirectToAction("Edit", "Title", new { id = model.TitleId });
                if (model.Redirect == "contact")
                    return RedirectToAction("Edit", "Contact", new { id = model.ReviewerId });
                return RedirectToAction("Search");
            }
            return View(model);
        }
コード例 #3
0
ファイル: ReviewData.cs プロジェクト: ericjohnolson/wave
        public void Insert(Review model, int createdBy)
        {
            var newReview = new review
                    {
                        copy_link = model.CopyLink,
                        date_reviewed = model.DateReviewed,
                        original_link = model.OriginalLink,
                        review_text = model.ReviewText,
                        reviewedby = model.ReviewerId,
                        title_id = model.TitleId,
                        venue = model.Venue,
                        createdat = DateTime.Now,
                        createdby = createdBy,
                        updatedat = DateTime.Now,
                        updatedby = createdBy,
                    };

                dbContext.reviews.Add(newReview);
                dbContext.SaveChanges();
        }
コード例 #4
0
ファイル: ReviewData.cs プロジェクト: ericjohnolson/wave
 public Review GetById(int id)
 {
     var model = dbContext.reviews.FirstOrDefault(x => x.id == id);
         if (model == null)
             return null;
         Review review = new Review
         {
             Id = model.id,
             CopyLink = model.copy_link,
             DateReviewed = model.date_reviewed,
             OriginalLink = model.original_link,
             ReviewText = model.review_text,
             Venue = model.venue,
             ReviewerId = model.reviewedby,
             ReviewerName = model.reviewedby > 0 ? model.review_contact.firstname + " " + model.review_contact.lastname + " (" +
                 (model.review_contact.is_primary ? model.review_contact.organization : model.review_contact.organization_alt) + ")" : string.Empty,
             TitleId = model.title_id,
             TitleName = model.review_title.title1,
             TitlePubDate = model.review_title.date_published
         };
         review.TitleName = review.TitleName + " (" + review.TitlePubDate.ToShortDateString() + ")";
         return review;
 }
コード例 #5
0
ファイル: ReviewData.cs プロジェクト: ericjohnolson/wave
 public void Update(Review model, int updatedby)
 {
     var obj = dbContext.reviews.First(x => x.id == model.Id);
         {
             obj.copy_link = model.CopyLink;
             obj.date_reviewed = model.DateReviewed;
             obj.original_link = model.OriginalLink;
             obj.review_text = model.ReviewText;
             obj.reviewedby = model.ReviewerId;
             obj.title_id = model.TitleId;
             obj.venue = model.Venue;
             obj.updatedat = DateTime.Now;
             obj.updatedby = updatedby;
             dbContext.SaveChanges();
         }
 }
コード例 #6
0
        private void Validate(Review model)
        {
            if (model.ReviewerId < 1)
                ModelState.AddModelError("ReviewerId", "Please select a valid Contact from the auto complete choices");

            if (model.TitleId < 1)
                ModelState.AddModelError("TitleId", "Please select a valid Title from the auto complete choices");

            if (!ModelState.IsValid)
                ModelState.AddModelError(string.Empty, "Please fix the errors below.");
        }
コード例 #7
0
        private void ParseQueryString(HttpRequestBase Request, Review model, bool isCreate)
        {
            model.Redirect = string.Empty;
            if (!string.IsNullOrEmpty(Request.QueryString["title"]))
            {
                model.Redirect = "title";
                if (isCreate)
                {
                    model.TitleId = Convert.ToInt32(Request.QueryString["title"]);
                    model.TitleName = data.GetTitleDisplayNameById(model.TitleId);
                }
            }
            else if (!string.IsNullOrEmpty(Request.QueryString["contact"]))
            {
                model.Redirect = "contact";

                if (isCreate)
                {
                    model.ReviewerId = Convert.ToInt32(Request.QueryString["contact"]);
                    model.ReviewerName = data.GetContactDisplayNameById(model.ReviewerId);
                }
            }
        }
コード例 #8
0
 private void LoadLists(Review model)
 {
     var titleId = model.TitleId.ToString();
     var titleName = string.IsNullOrEmpty(model.TitleName) ? "Search for a Title" : model.TitleName;
     var contactId = model.ReviewerId.ToString();
     var contactName = string.IsNullOrEmpty(model.ReviewerName) ? "Search for a Contact" : model.ReviewerName;
     var contacts = new List<SelectListItem> { new SelectListItem { Text = contactName, Value = contactId } };
     var titles = new List<SelectListItem> { new SelectListItem { Text = titleName, Value = titleId } };
     model.Contacts = new SelectList(contacts, "Value", "Text", null);
     model.Titles = new SelectList(titles, "Value", "Text", null);
 }