Пример #1
0
 public ActionResult Index()
 {
     List<GroupViewModel> groupViewModels = new List<GroupViewModel>();
     foreach (var groupUser in db.GroupUserRelations.Where(s => s.User.UserName == HttpContext.User.Identity.Name).ToList())
     {
         Group group = groupUser.Group;
         GroupViewModel groupViewModel = new GroupViewModel() {
         GroupName = group.GroupName,
         Status = group.Status,
         };
         groupViewModels.Add(groupViewModel);
     }
     return View(groupViewModels);
 }
Пример #2
0
 //
 // GET: /Group/Edit/5
 //[Authorize(Roles = "SuperAdmin")]
 public ActionResult Edit(int? id)
 {
     if (id == null)
     {
         return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
     }
     Group group = db.Groups.Find(id);
     GroupViewModel groupViewModel = new GroupViewModel()
     {
         GroupName = group.GroupName,
         //Password = group.Password,
         //CreatedBy = group.CreatedBy,
         //CreatedDate = group.CreatedDate,
         Status = group.Status,
         //ModifiedBy = group.ModifiedBy,
         //ModifiedDate = group.ModifiedDate,
     };
     if (group == null)
     {
         return HttpNotFound();
     }
     return View(groupViewModel);
 }
Пример #3
0
 public ActionResult Edit(int id, GroupViewModel groupViewModel)
 {
     try
     {
         // TODO: Add update logic here
         if (ModelState.IsValid)
         {
             Group group = new Group()
             {
                 GroupId = id,
                 GroupName = groupViewModel.GroupName,
                 //Password = groupViewModel.Password,
                 //CreatedBy = groupViewModel.CreatedBy,
                 //CreatedDate = groupViewModel.CreatedDate,
                 Status = groupViewModel.Status,
                 //ModifiedBy = groupViewModel.ModifiedBy,
                 //ModifiedDate = groupViewModel.ModifiedDate,
             };
             db.Entry(group).State = EntityState.Modified;
             db.SaveChanges();
             return RedirectToAction("Index");
         }
         return View(groupViewModel);
     }
     catch
     {
         return View();
     }
 }
Пример #4
0
        public ActionResult Create(GroupViewModel groupViewModel)
        {
            try
            {
                // TODO: Add insert logic here
                if (ModelState.IsValid)
                {
                    Group group = new Group()
                    {
                        GroupName = groupViewModel.GroupName,
                        //Password = groupViewModel.Password,
                        //CreatedBy = groupViewModel.CreatedBy,
                        //CreatedDate = groupViewModel.CreatedDate,
                        Status = groupViewModel.Status,
                        //ModifiedBy = groupViewModel.ModifiedBy,
                        //ModifiedDate = groupViewModel.ModifiedDate,

                    };
                    db.Groups.Add(group);
                    //db.SaveChanges();
                    if (!(bool)Session["isAdmin"])
                    {
                        GroupsUsers groupsUsers = new GroupsUsers()
                        {
                            GroupId = group.GroupId,
                            UserId = (int)HttpContext.Session["UserId"],
                        };
                        db.GroupUserRelations.Add(groupsUsers);
                    }

                    db.SaveChanges();

                    //IdentityManager im = new IdentityManager();
                    //ApplicationUser user = new ApplicationUser() { UserName = group.GroupName, };
                    //im.CreateUser(user, group.Password);
                    return RedirectToAction("AddMember", new { id=group.GroupId});
                }
                return View(groupViewModel);

            }
            catch
            {
                return View();
            }
        }