Beispiel #1
0
        public ActionResult CreateEdit(int?id)
        {
            if (id == null) // Create
            {
                return(View(new GroupsCreateEditViewModel()
                {
                    UserID = AuthenticationService.LoggedUser.Id
                }));
            }

            else if (id > 0) // Edit
            {
                Group group = groupRepo.GetById(id.Value);

                if (group != null && group.UserID == AuthenticationService.LoggedUser.Id)
                {
                    GroupsCreateEditViewModel g = new GroupsCreateEditViewModel()
                    {
                        Id     = group.Id,
                        Name   = group.Name,
                        UserID = group.UserID
                    };

                    return(View(g));
                }
            }

            return(RedirectToAction("Index"));
        }
Beispiel #2
0
        public ActionResult Delete(int?id)
        {
            if (id != null)
            {
                Group group = groupRepo.GetById(id.Value);

                if (group != null && group.UserID == AuthenticationService.LoggedUser.Id)
                {
                    GroupsCreateEditViewModel g = new GroupsCreateEditViewModel()
                    {
                        Id   = group.Id,
                        Name = group.Name
                    };

                    return(View(g));
                }
            }

            return(RedirectToAction("Index"));
        }
Beispiel #3
0
        public ActionResult CreateEdit(GroupsCreateEditViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            Group group;


            if (model.Id > 0) // Edit
            {
                group = groupRepo.GetById(model.Id);

                if (group == null || group.UserID != model.UserID)
                {
                    return(HttpNotFound());
                }
            }

            else // Create
            {
                group = new Group()
                {
                    UserID = AuthenticationService.LoggedUser.Id
                };
            }

            if (group.UserID == AuthenticationService.LoggedUser.Id)
            {
                group.Name = model.Name;

                groupRepo.Save(group);

                return(RedirectToAction("Index"));
            }

            return(HttpNotFound());
        }