public ActionResult CreateOwner(Guid id)
        {
            ViewData["PageTitle"] = "New Owner";

              AnimalOwner o = new AnimalOwner();
              o.Animal = (from a in this.db.Animals where a.Id == id select a).First();
              o.Starting = DateTime.Today;
              //s.Person = (from p in this.db.Members where p.Id == personId select p).First();
              //s.Activated = DateTime.Today;

              Session.Add("NewOwnerGuid", o.Id);
              ViewData["NewOwnerGuid"] = Session["NewOwnerGuid"];

              return InternalEditOwner(o);
        }
Esempio n. 2
0
        public void ReportFormat()
        {
            string animalName = "Animal Bob";
              DateTime starting = DateTime.Now;
              DateTime? ending = null;
              var owner = new Member { FirstName = "Fred", LastName = "Rider" };
              var ao = new AnimalOwner {
            Owner = owner,
            Animal = new Animal { Name = animalName },
            Starting = starting,
            Ending = ending
              };

              var html = ao.GetReportHtml();
              Assert.IsTrue(html.Contains(animalName), "animal name");
              Assert.IsTrue(html.Contains(owner.FullName), "owner name");
              Assert.IsTrue(html.Contains(starting.ToString()), "starting");
        }
        public ActionResult CreateOwner(Guid id, FormCollection fields)
        {
            if (Session["NewOwnerGuid"] != null && Session["NewOwnerGuid"].ToString() != fields["NewOwnerGuid"])
              {
            throw new InvalidOperationException("Invalid operation. Are you trying to re-create an ownership?");
              }
              Session.Remove("NewOwnerGuid");

              ViewData["PageTitle"] = "New Owner";

              AnimalOwner o = new AnimalOwner();
              o.Animal = (from a in this.db.Animals where a.Id == id select a).First();
              //    um.Person = (from p in this.db.Members where p.Id == personId select p).First();
              this.db.AnimalOwners.Add(o);
              return InternalSaveOwner(o, fields);
        }
        private ActionResult InternalSaveOwner(AnimalOwner o, FormCollection fields)
        {
            TryUpdateModel(o, new string[] { "IsPrimary", "Starting", "Ending" });

              if (string.IsNullOrEmpty(fields["pid_a"]))
              {
            ModelState.AddModelError("Owner", "Required. Please pick from list.");

              }
              else
              {
            Guid personId = new Guid(fields["pid_a"]);
            Member member = (from m in this.db.Members where m.Id == personId select m).First();
            o.Owner = member;
              }

              if (ModelState.IsValid)
              {
            this.db.SaveChanges();
            TempData["message"] = "Saved";
            return RedirectToAction("ClosePopup");
              }

              return InternalEditOwner(o);
        }
 private ActionResult InternalEditOwner(AnimalOwner o)
 {
     return View("EditOwner", o);
 }