Esempio n. 1
0
        public ActionResult Edit(TeamsEditVM model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            OvmDbContext context = new OvmDbContext();

            Team team = new Team();

            team.Id   = model.Id;
            team.Name = model.Name;

            if (model.ProjectId != 0)
            {
                team.ProjectId = model.ProjectId;
            }

            context.Teams.AddOrUpdate(t => t.Id, team);
            context.SaveChanges();
            context.Dispose();

            return(RedirectToAction("Index"));
        }
Esempio n. 2
0
        public ActionResult Edit(int?id)
        {
            TeamsEditVM  item;
            OvmDbContext context = new OvmDbContext();

            if (id == null)
            {
                item = new TeamsEditVM();
            }
            else
            {
                Team team = context.Teams.Find(id.Value);

                item = new TeamsEditVM
                {
                    Id        = id.Value,
                    Name      = team.Name,
                    ProjectId = team.ProjectId ?? 0
                };
            }

            item.Projects = context.Projects.Select(p => new ProjectsPair
            {
                Name = p.Name,
                Id   = p.Id
            }).ToList();

            context.Dispose();

            return(View(item));
        }