Exemplo n.º 1
0
        public ActionResult Add(Team team)
        {
            ViewBag.sportsList = ItemListCreator.Sports();

            if (ModelState.IsValid)
            {
                if (_teamRepo.Add(team))
                {
                    ViewBag.Success = "Added succesfully";
                    return View();
                }
            }

            ViewBag.Error = "Error adding an athlete!";

            return View();
        }
Exemplo n.º 2
0
        public IHttpActionResult Add(Team team)
        {
            try
            {
                _db.Team.Add(team);
                _db.SaveChanges();

                return
                    new ItemCreatedHttpResult<Team>(team, Request, team.TeamId, "GetTeamById");
            }
            catch (Exception ex)
            {
                HttpResponseMessage responseMsg = new HttpResponseMessage(HttpStatusCode.Conflict);
                responseMsg.Content = new StringContent(/*ex.Message.ToString()*/"Either duplicate key or duplicate name",
                                                            Encoding.UTF8, "text/plain");
                IHttpActionResult response = ResponseMessage(responseMsg);

                return response;
            }
        }
Exemplo n.º 3
0
        public ActionResult Update(Team team)
        {
            if (ModelState.IsValid)
            {
                if (_teamRepo.Update(team))
                {
                    TempData["Success"] = "Updated succesfully";
                    return RedirectToAction("List");
                }
            }

            TempData["Error"] = "Error updating an athlete!";
            return RedirectToAction("List");
        }
Exemplo n.º 4
0
        public IHttpActionResult Update(Team team)
        {
            try
            {
                Team teamToUpdate = _db.Team.Where(t => t.TeamId == team.TeamId).First();

                teamToUpdate.Name = team.Name;
                teamToUpdate.Sport = team.Sport;
                _db.SaveChanges();

                return Ok();
            }
            catch (Exception ex)
            {
                return InternalServerError();
            }
        }