Exemple #1
0
        public IHttpActionResult CreateGroup(CreateGroupViewModel model)
        {
            if (model == null)
            {
                return(this.BadRequest("Group name must be provided"));
            }

            if (!ModelState.IsValid)
            {
                return(this.BadRequest(this.ModelState));
            }

            var currentUser   = this.sessionService.GetCurrentUser();
            var existingGroup = this.groupService.GetGroupByName(model.Name);

            if (existingGroup != null)
            {
                return(this.Content(HttpStatusCode.Conflict, "Group with that name already exists."));
            }

            var group = this.groupService.CreateGroup(model.Name, currentUser);

            var members = group.Users.Select(u => new DisplayUserViewModel(u.Email, u.FirstName, u.LastName, u.DisplayName, u.UserName))
                          .ToList();
            var groupModel = new DisplayGroupViewModel(group.Name, group.Admin.UserName, members);

            return(this.Content(HttpStatusCode.Created, groupModel));
        }
Exemple #2
0
        public IActionResult Index()
        {
            var model = new List <DisplayGroupViewModel>();

            var dbGroups = _hdDbContext.Groups.Where(t => true).ToList();

            foreach (var dbGroup in dbGroups)
            {
                var item = new DisplayGroupViewModel();
                item.GroupName = dbGroup.Name;
                item.Id        = dbGroup.Id;

                var dbIndustry = _hdDbContext.Industries.FirstOrDefault(t => t.Id == dbGroup.IndustryId);
                item.IndustryName = dbIndustry.Name;
                model.Add(item);
            }

            return(View(model));
        }