Ejemplo n.º 1
0
        public ActionResult TrainerDetails(Trainer w)
        {
            if (ModelState.IsValid)
            {
                User     u = db.Users.Find(int.Parse(Session["UserID"].ToString()));
                Customer c = db.Customers.Where(x => x.EMail == u.EMail).FirstOrDefault();
                TrainerCustomerATable t = db.TrainerCustomerATables.Where(x => x.CustomerID == c.ID).FirstOrDefault();

                if (t == null)
                {
                    TrainerCustomerATable trainerCustomer = new TrainerCustomerATable();
                    trainerCustomer.CustomerID = c.ID;
                    trainerCustomer.TrainerID  = w.ID;
                    db.TrainerCustomerATables.Add(trainerCustomer);
                    db.SaveChanges();
                    Trainer final = db.Trainers.Find(w.ID);
                    TempData["Success"] = "Your trainer is now " + final.FirstName + " " + final.LastName;
                    return(RedirectToAction("TrainerList", "Customer"));
                }
                else
                {
                    t.TrainerID = w.ID;
                    db.Entry(t).CurrentValues.SetValues(t);
                    db.SaveChanges();
                    Trainer final = db.Trainers.Find(w.ID);
                    TempData["Success"] = "Your trainer is now " + final.FirstName + " " + final.LastName;
                    return(RedirectToAction("TrainerList", "Customer"));
                }
            }
            return(View());
        }
Ejemplo n.º 2
0
        public ActionResult TrainerList()
        {
            User     u = db.Users.Find(int.Parse(Session["UserID"].ToString()));
            Customer c = db.Customers.Where(x => x.EMail == u.EMail).FirstOrDefault();
            TrainerCustomerATable t = db.TrainerCustomerATables.Where(x => x.CustomerID == c.ID).FirstOrDefault();

            if (t != null)
            {
                TempData["Info"] = "Your trainer is " + t.Trainer.FirstName + " " + t.Trainer.LastName;
            }
            else if (t == null)
            {
                TempData["Info"] = "Your do not have a current trainer. You can choose one below.";
            }
            return(View(db.Trainers.ToList()));
        }
        public ActionResult TrainerDetails(Trainer w)
        {
            if (ModelState.IsValid)
            {
                User u = db.Users.Find(int.Parse(Session["UserID"].ToString()));
                Customer c = db.Customers.Where(x => x.EMail == u.EMail).FirstOrDefault();
                TrainerCustomerATable t = db.TrainerCustomerATables.Where(x => x.CustomerID == c.ID).FirstOrDefault();

                if (t == null)
                {
                    TrainerCustomerATable trainerCustomer = new TrainerCustomerATable();
                    trainerCustomer.CustomerID = c.ID;
                    trainerCustomer.TrainerID = w.ID;
                    db.TrainerCustomerATables.Add(trainerCustomer);
                    db.SaveChanges();
                    Trainer final = db.Trainers.Find(w.ID);
                    TempData["Success"] = "Your trainer is now " + final.FirstName + " " + final.LastName;
                    return RedirectToAction("TrainerList", "Customer");
                }
                else
                {
                    t.TrainerID = w.ID;
                    db.Entry(t).CurrentValues.SetValues(t);
                    db.SaveChanges();
                    Trainer final = db.Trainers.Find(w.ID);
                    TempData["Success"] = "Your trainer is now " + final.FirstName + " " + final.LastName;
                    return RedirectToAction("TrainerList", "Customer");
                }
            }
            return View();
        }