public bool UpdateCoach(CoachEdit model)
 {
     using (var ctx = new ApplicationDbContext())
     {
         var entity =
             ctx
             .Coaches
             .Single(e => e.CoachId == model.CoachId);
         entity.CoachId       = model.CoachId;
         entity.FirstName     = model.FirstName;
         entity.LastName      = model.LastName;
         entity.PositionCoach = model.PositionCoach;
         entity.AreRecruiting = model.AreRecruting;
         return(ctx.SaveChanges() == 1);
     }
 }
        public IHttpActionResult Put(CoachEdit coach)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateCoachService();

            if (!service.UpdateCoach(coach))
            {
                return(InternalServerError());
            }

            return(Ok());
        }
        public ActionResult Edit(int id)
        {
            var service = CreateCoachService();
            var detail  = service.GetCoachById(id);
            var model   =
                new CoachEdit
            {
                CoachId       = detail.CoachId,
                FirstName     = detail.FirstName,
                LastName      = detail.LastName,
                PositionCoach = detail.PositionCoach,
                AreRecruting  = detail.AreRecruting
            };

            return(View(model));
        }
Ejemplo n.º 4
0
        public bool UpdateCoach(CoachEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Coaches
                    .Single(e => e.CoachId == model.CoachId && e.OwnerId == _userId);

                entity.FirstName = model.FirstName;
                entity.LastName  = model.LastName;
                entity.Email     = model.Email;
                entity.TeamId    = model.TeamId;

                return(ctx.SaveChanges() == 1);
            }
        }
Ejemplo n.º 5
0
        public ActionResult Edit(int id)
        {
            ViewBag.TeamId = new SelectList(_db.Teams.ToList(), "TeamId", "Name");

            var service = CreateCoachService();
            var detail  = service.GetCoachById(id);
            var model   =
                new CoachEdit
            {
                CoachId   = detail.CoachId,
                FirstName = detail.FirstName,
                LastName  = detail.LastName,
                Email     = detail.Email,
                TeamId    = detail.TeamId
            };

            return(View(model));
        }
        public bool UpdateCoach(CoachEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Coach
                    .Single(e => e.CoachName == model.CoachName && e.OwnerId == _userId);

                entity.CoachName          = model.CoachName;
                entity.SeasonRecord       = model.SeasonRecord;
                entity.OverallRecord      = model.OverallRecord;
                entity.MarchMadnessRecord = model.MarchMadnessRecord;
                entity.TeamId             = model.TeamId;


                return(ctx.SaveChanges() == 1);
            }
        }
        public ActionResult Edit(int id, CoachEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            if (model.CoachId != id)
            {
                ModelState.AddModelError("", "this id does not match a school please enter the correct one");
                return(View(model));
            }
            var service = CreateCoachService();

            if (service.UpdateCoach(model))
            {
                TempData["save result"] = "your school was updated";
                return(RedirectToAction("Index"));
            }
            ModelState.AddModelError("", "school can not be updated");
            return(View(model));
        }
Ejemplo n.º 8
0
        public ActionResult Edit(int id, CoachEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.CoachId != id)
            {
                ModelState.AddModelError("", "Id Mismatch");
                return(View(model));
            }

            var service = CreateCoachService();

            if (service.UpdateCoach(model))
            {
                TempData["SaveResult"] = "Your coach was updated.";
                return(RedirectToAction("Index"));
            }
            ModelState.AddModelError("", "Your coach could not be updated.");
            return(View(model));
        }