示例#1
0
        public ActionResult Edit( EditTeamVM TeamVM)
        {

            var user = CurrentUser();
            var team = db.Teams.FirstOrDefault(t => t.ID == TeamVM.TeamID);

            if (!ModelState.IsValid)
            {
                TeamVM.Team = team;
                return View(TeamVM);
            }

            if (team == null)
            {
                Messaging.Add(Message.LevelEnum.alert_danger, "something went wrong trying to update the Team.", Message.TypeEnum.TemporaryAlert, user);
            }
            else if (user.IsTeamAdmin && user.TeamID ==TeamVM.TeamID)
            {
                if (!string.IsNullOrEmpty(TeamVM.Description))
                    team.Description = TeamVM.Description;

                if (TeamVM.TeamImageID>0)
                team.ImageID = TeamVM.TeamImageID;

                if (!string.IsNullOrEmpty(TeamVM.Name))
                {
                    team.Name = TeamVM.Name;
                }

                team.Availability = TeamVM.Availability;

                Messaging.Add(Message.LevelEnum.alert_success, "Team details updated", Message.TypeEnum.StickyAlert, user);
                db.SaveChanges();
                return RedirectToAction("Details", new { TeamName = team.Name.Replace(" ","") });
            }
            else
            {
                Messaging.Add(Message.LevelEnum.alert_danger, "You don't have permission to edit this Team.", Message.TypeEnum.TemporaryAlert, user);
            }

            db.SaveChanges();
            //if we get here something went wrong so send back the edit view.
            if (team != null)
            {
                TeamVM.Team = team;
                TeamVM.Availability = team.Availability;
            }            
            return View(TeamVM);
        }
示例#2
0
        public ActionResult Edit(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            Team team = db.Teams.Find(id);
            if (team == null)
            {
                return HttpNotFound();
            }

            var VM = new EditTeamVM
            {
                Team = team,
                TeamID = team.ID,
                Availability = team.Availability
            };
            return View(VM);
        }