Exemple #1
0
        public ActionResult Create(AddUserViewModel newUserViewModel)
        {
            if (ModelState.IsValid)
            {
                var newUserEntity = mapper.Map <AddUserViewModel, User>(newUserViewModel);
                context.Users.Add(newUserEntity);
                context.SaveChanges();

                return(RedirectToAction("Index"));
            }
            else
            {
                return(View());
            }
        }
Exemple #2
0
        public ActionResult Create(AddProjectViewModel newProjectViewModel)
        {
            try
            {
                // TODO: Add insert logic here
                var addProjectEntity = mapper.Map <AddProjectViewModel, Project>(newProjectViewModel);
                context.Projects.Add(addProjectEntity);
                context.SaveChanges();


                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Exemple #3
0
        public ActionResult Edit(EditSprintViewModel model)
        {
            try
            {
                // TODO: Add update logic here
                if (ModelState.IsValid)
                {
                    var entitySprint = mapper.Map <EditSprintViewModel, Sprint>(model);

                    entitySprint.Users.Where(m => !model.SelectedUsers.Contains(m.UserID)).ToList().ForEach(user => entitySprint.Users.Remove(user));

                    var selectedUsers = entitySprint.Users.Select(m => m.UserID);
                    context.Users.Where(m => !model.SelectedUsers.Except(selectedUsers).Contains(m.UserID)).ToList()
                    .ForEach(user => entitySprint.Users.Add(user));


                    entitySprint.StartDate = model.StartDate;
                    entitySprint.EndDate   = model.EndDate;
                    entitySprint.ScrumGoal = model.ScrumGoal;
                    entitySprint.ProjectID = model.ProjectID;
                    context.SaveChanges();

                    return(RedirectToAction("Index"));
                }

                var entitySprintUsers    = context.Users;
                var sprintViewModelUsers = mapper.Map <IEnumerable <User>, IEnumerable <UserViewModel> >(entitySprintUsers);

                model.Users = sprintViewModelUsers;

                return(View(model));
            }
            catch
            {
                return(View());
            }
        }