예제 #1
0
        public async Task <ActionResult> Create(CreateGroupModel model)
        {
            using (var identityGroupService = new IdentityGroupService())
            {
                if (!ModelState.IsValid)
                {
                    return(PartialView("_Create", model));
                }

                var group = new Group()
                {
                    Name        = model.Name,
                    DisplayName = model.Name,
                    Description = model.Description
                };

                var result = await identityGroupService.CreateAsync(group);

                if (result.Succeeded)
                {
                    return(Json(new { success = true }));
                }

                AddErrors(result);

                return(PartialView("_Create", model));
            }
        }
예제 #2
0
        public async Task <IActionResult> CreateGroup([FromBody] CreateGroupModel groupModel)
        {
            try
            {
                var user = await _context.Users
                           .FirstOrDefaultAsync(x => x.UserName.Equals(User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value));

                var group = new Group();
                group.Name = groupModel.GroupName;
                _context.Groups.Add(group);
                await _context.SaveChangesAsync();

                var userGroups = new UsersGroups();
                userGroups.UserId  = user.Id;
                userGroups.GroupId = group.Id;
                _context.UsersGroups.Add(userGroups);
                await _context.SaveChangesAsync();

                group.Users = new List <UsersGroups>()
                {
                    userGroups
                };
                return(new OkObjectResult(group.MapGroupToModel(_context, User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value)));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #3
0
        public IActionResult Post([FromBody] CreateGroupModel model)
        {
            var groupKey = this.groupManager.NewGroup(model.PhoneNumber);

            this.Response.StatusCode = StatusCodes.Status201Created;
            return(new JsonResult(new { key = groupKey, receivePhoneNumber = this.configuration.GetValue <string>("TwilioPhoneNumber") }));
        }
예제 #4
0
        public async Task <IActionResult> RenameGroup(string id, [FromBody] CreateGroupModel groupModel)
        {
            try
            {
                var group = await _context.Groups
                            .Include("Users.User")
                            .FirstOrDefaultAsync(x => x.Id.ToString().Equals(id));

                if (group == null)
                {
                    return(NotFound());
                }
                var userExists = group.Users.FirstOrDefault(x => x.User.UserName.Equals(User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value));
                if (userExists == null)
                {
                    return(new BadRequestObjectResult(new List <ErrorViewModel>()
                    {
                        new ErrorViewModel()
                        {
                            Code = "UserNotFound", Description = "User is not group member."
                        }
                    }));
                }
                group.Name = groupModel.GroupName;
                await _context.SaveChangesAsync();

                return(NoContent());
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #5
0
        public async Task <ActionResult <GroupDto> > CreateGroup(CreateGroupModel input)
        {
            var user = await _userManger.GetUserAsync(User);

            if (user == null)
            {
                return(BadRequest("User not found"));
            }

            var group = new Group {
                Name = input.Name
            };

            user.Group   = group;
            user.IsAdmin = true;

            try
            {
                await _uow.SaveChangesAsync();
            }
            catch (ValidationException ex)
            {
                return(BadRequest(ex.Message));
            }

            return(CreatedAtAction(nameof(GetGroup), new GroupDto(group)));
        }
 public ActionResult Group(int id = 0)
 {
     using (var db = new Entities())
     {
         var model = new CreateGroupModel();
         model.roles = db.asp_Role.Select(x => new RoleData {
             name = x.name, description = x.description
         }).ToList();
         var data = db.asp_Group.FirstOrDefault(x => x.id == id);
         if (data != null)
         {
             model.id          = data.id;
             model.name        = data.name;
             model.description = data.description;
             foreach (var item in model.roles)
             {
                 if (data.asp_Role.Any(x => x.name == item.name))
                 {
                     item.check = true;
                 }
             }
         }
         return(PartialView(model));
     }
 }
예제 #7
0
        public IActionResult CreateGroup(
            [Bind(nameof(CreateGroupModel.GroupName))] CreateGroupModel model)

        {
            if (ModelState.IsValid)
            {
                try
                {
                    model.Create();
                    model.Response = new ResponseModel("Group configuration creation successful.", ResponseType.Success);
                    return(RedirectToAction("Index"));
                }
                catch (DuplicationException ex)
                {
                    model.Response = new ResponseModel(ex.Message, ResponseType.Failure);
                    // error logger code
                }
                catch (Exception ex)
                {
                    model.Response = new ResponseModel("Group configuration creation failued.", ResponseType.Failure);
                    // error logger code
                }
            }
            return(View(model));
        }
예제 #8
0
        //创建群按钮
        private void buttonCreateGroup_Click(object sender, EventArgs e)
        {
            checkGroupAmount();
            if (tomanyGroup)
            {
                return;
            }
            if (textBoxGroupName.Text == "")
            {
                labelTip.Text = "请输入公司名字...";
                return;
            }
            //群的基本信息
            CreateGroupModel createGroupModel = new CreateGroupModel();

            createGroupModel.Groupname = this.textBoxGroupName.Text;
            if (this.radioButtonNoVerify.Checked)  //不需要验证按钮被勾选
            {
                createGroupModel.VerifyModel = 1;
            }
            else
            {
                createGroupModel.VerifyModel = 0;
            }
            string msgContent = Coding <CreateGroupModel> .encode(createGroupModel);

            MsgModel mm = new MsgModel(MessageProtocol.CREATE_GROUP_CREQ, AppInfo.USER_NAME, "", msgContent, DateTime.Now.ToString());

            MainMgr.Instance.msgMgr.sendMessage(MessageProtocol.GROUP, mm);
            this.textBoxGroupName.Text = "";
        }
예제 #9
0
        private int AddGroup(CreateGroupModel group)
        {
            string expressSql = "createStudyGroup";

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                connection.Open();
                SqlCommand command = new SqlCommand(expressSql, connection)
                {
                    CommandType = System.Data.CommandType.StoredProcedure
                };
                SqlParameter namePar = new SqlParameter // parameter for enter name
                {
                    ParameterName = "@nameSG",
                    Value         = group.NameStudyGroup
                };
                command.Parameters.Add(namePar);             // add
                SqlParameter idTeacherPar = new SqlParameter // parameter for id
                {
                    ParameterName = "@IdTeach",
                    Value         = group.IdTeacher
                };
                command.Parameters.Add(idTeacherPar);
                int result = (int)command.ExecuteScalar();
                return(result);
            }
        }
예제 #10
0
        public async Task <IActionResult> GetTest(CreateGroupModel dto)
        {
            Console.WriteLine("---------------");
            dto.Department[0] = 5394703153207343904;
            var dd = await _exmailHelper.UpdateGroup(dto);

            return(new JsonResult(dd));
        }
예제 #11
0
        public CreateGroupAction(Transport <object[]> transport)
        {
            Context = transport.Dependencies.Context;
            mapper  = transport.Dependencies.Mapper;

            UserData   = (NewUserModel)transport.Data[0];
            GroupData  = (CreateGroupModel)transport.Data[1];
            MediaLinks = (List <MediaLink>)transport.Data[2];
        }
예제 #12
0
 public IHttpActionResult Post([FromBody] CreateGroupModel model)
 {
     using (var t = Repository.BeginTransaction())
     {
         var group = GroupService.CreateGroup(model.Name);
         t.Commit();
         return(Json(group));
     }
 }
예제 #13
0
        public async Task <ActionResult> CreateGroup([Bind(Include = "name")] CreateGroupModel model)
        {
            ActionResult result = null;

            await Groups.CreateGroup(model.Name);

            result = Redirect(Request.UrlReferrer.ToString());

            return(result);
        }
예제 #14
0
        private static CreateGroupModel CreateGroupModel(CreateGroupRequest request, int userId)
        {
            var groupModel = new CreateGroupModel
            {
                CreatorId        = userId,
                GroupName        = request.GroupName,
                GroupDescription = request.GroupDescription
            };

            return(groupModel);
        }
예제 #15
0
        public ActionResult Create()
        {
            ViewBag.Genders       = Gender();
            ViewBag.CheckPoints   = CheckPoints();
            ViewBag.Nationalities = Nationalities();

            var model = new CreateGroupModel();

            model.Infoes.Add(new InfoVisitorModel());
            return(View(model));
        }
예제 #16
0
        public CreateGroupVm(IResponseService responseService, IRepository repository, NavigationManager navigationManager, ICurrentUserService currentUser)
        {
            _responseService = responseService;
            _repository      = repository;
            _currentUser     = currentUser;

            item               = new CreateGroupModel();
            notification       = new NotificationModel();
            Games              = new GetAllGames();
            _navigationManager = navigationManager;
        }
예제 #17
0
 public IActionResult Post([FromBody] CreateGroupModel newGroup, [FromServices] ICreateGroupCommand createGroupCommand)
 {
     if (ModelState.IsValid)
     {
         var storedGroup = createGroupCommand.Execute(newGroup);
         return(Created(Request.Path.Value + "/" + storedGroup.Id, storedGroup));
     }
     else
     {
         return(BadRequest("Something went wrong"));
     }
 }
예제 #18
0
        public ActionResult <ChatInfo> CreateGroupChat([FromBody] CreateGroupModel model)
        {
            model.Members.Add(User.Identity.Name);
            var chat     = _chatService.CreateGroupChat(User.Identity.Name, model.Name, model.Members);
            var chatInfo = _mapper.Map <GroupChatInfo>(chat);

            var activeChatUsers = _subscriptionManager.GetActiveChatMembers(chatInfo.Id);

            _hub.Clients.Clients(activeChatUsers.ToList()).ChatCreated(chatInfo);

            return(Ok());
        }
예제 #19
0
        public static async Task <Uri> CreateAsync(string domainName, string groupName, List <string> userNames)
        {
            CreateGroupModel fromBodyGoup = new CreateGroupModel();

            fromBodyGoup.domainName = domainName;
            fromBodyGoup.groupName  = groupName;
            fromBodyGoup.userNames  = userNames;
            HttpResponseMessage response = await MyClient.client.PostAsJsonAsync("security/group", fromBodyGoup);

            response.EnsureSuccessStatusCode();
            return(response.Headers.Location);
        }
예제 #20
0
        /// <summary>
        /// 更新邮组
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task <GroupModel> UpdateGroup(CreateGroupModel dto)
        {
            string     url   = $"https://api.exmail.qq.com/cgi-bin/group/update?access_token={this.Email_token}";
            GroupModel model = await HttpHelper.PostHttpAsync <GroupModel, CreateGroupModel>(url, dto);

            if (model.Errcode != 0)
            {
                this.Errmsg = model.Errmsg;
                throw new Exception($"更新邮箱组失败:{model.Errcode}-{this.Errmsg}");
            }
            return(await Task.FromResult(model));
        }
예제 #21
0
        public ActionResult CreateGroup()
        {
            CreateGroupModel model = new CreateGroupModel();

            using (GrumServiceClient client = new GrumServiceClient())
            {
                model.Students = client.getClassById(2).StudentList
                                 .Select(s => new Models.Student(s.Id, s.Name))
                                 .ToList();
            }

            return(View(model));
        }
예제 #22
0
        public IHttpActionResult CreateDomain([FromBody] CreateGroupModel group)
        {
            if (group.groupName.Equals(null) || group.groupName == string.Empty)
            {
                return(BadRequest("enter a value for group name"));
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            long       groupId = Storage.createGroup(group.domainName, group.groupName, group.userNames);
            GroupModel gp      = Storage.getGroup(group.domainName, groupId);

            return(CreatedAtRoute("GetGroup", new { domainName = group.domainName, groupId = groupId }, group));
        } //CreateDomain
예제 #23
0
        public IActionResult Create()
        {
            var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);

            var model = new CreateGroupModel();

            model.Universities = _universitiesService.GetUserUniversities(userId)
                                 .Select(c => new SelectListItem
            {
                Value = c.Id.ToString(),
                Text  = c.Name
            }).ToList();

            return(PartialView("_CreatePartial", model));
        }
예제 #24
0
        // POST: api/GroupsAPI
        //[ResponseType(typeof(CreateGroupModel))]
        public async Task <IActionResult> PostGroup(CreateGroupModel createGroupModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            //createGroupModel.VMEntity.WorldId = createGroupModel.WorldId;
            db.Entities.Add(createGroupModel.VMEntity);
            createGroupModel.VMGroup.Entity = createGroupModel.VMEntity;
            db.Groups.Add(createGroupModel.VMGroup);
            await db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = createGroupModel.VMGroup.GroupId }, createGroupModel.VMGroup));
        }
예제 #25
0
        private async Task <GroupVisitorDTO> CreateGroup(CreateGroupModel group, params InfoVisitorModel[] visitor)
        {
            await accountController.SetInitDataAsync();

            group.Infoes = visitor;
            var result = (await groupController.Create(group)) as RedirectToRouteResult;

            if (result == null)
            {
                return(null);
            }

            var groupResult = groupService.GetAll().LastOrDefault();

            return(groupResult);
        }
예제 #26
0
        public ActionResult <UserGroup> Create([FromBody] CreateGroupModel createGroupModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var user = _userAccountRepository.GetSingle(x => x.Id == createGroupModel.UserId);

            if (user == null)
            {
                return(BadRequest(new { Error = "Not a valid user" }));
            }

            return(_userGroupRepository.CreateAndAddNewGroup(createGroupModel.Name, user));
        }
예제 #27
0
        public async Task Validation_Fail_Model_GroupVisitor_GroupVisitorController()
        {
            var model = new CreateGroupModel();

            SimulateValidation(model);
            var result = (ViewResult)await groupController.Create(model);

            Assert.IsNotNull(result);

            var viewData = result.ViewData;
            var viewBag  = result.ViewBag;

            Assert.AreEqual(3, viewData.Values.Count);
            Assert.AreEqual(3, ((SelectList)viewBag.Genders).Count());
            Assert.AreEqual(4, ((SelectList)viewBag.CheckPoints).Count());
            Assert.AreEqual(5, ((SelectList)viewBag.Nationalities).Count());
        }
예제 #28
0
        public ActionResult CreateGroup(CreateGroupModel formModel)
        {
            int[] idList = formModel.Students.Where(s => s.Selected).Select(s => s.Id).ToArray();

            // check for students selected
            if (formModel.Students == null || idList.Length == 0)
            {
                return(Redirect("CreateGroup"));
            }

            using (GrumServiceClient client = new GrumServiceClient())
            {
                client.CreateGroup(formModel.Name, formModel.Students
                                   .Where(s => s.Selected)
                                   .Select(s => s.Id)
                                   .ToList());
            }
            return(Redirect("Rent"));
        }
예제 #29
0
        public IActionResult Create(CreateGroupModel model)
        {
            if (model == null)
            {
                return(BadRequest());
            }
            if (!ModelState.IsValid)
            {
                return(Ok(Json(ModelState
                               .Where(s => s.Value.Errors.Any())
                               .Select(s => new { Key = s.Key, Error = s.Value.Errors.Select(e => e.ErrorMessage).FirstOrDefault() }))));
            }

            var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);

            int?   universityId = null;
            string password     = null;

            if (model.RequirePassword)
            {
                password = model.Password;
            }
            if (model.RequireUniversity)
            {
                universityId = model.UniversityId;

                if (!_universitiesService.IsMember(model.UniversityId.Value, userId))
                {
                    return(BadRequest(Json("You are not a member of a selected university")));
                }
            }

            _groupsService.CreateGroup(userId, model.Name, universityId, password);

            return(Ok(Json(new { Redirect = Url.Action("Index", "Home") })));
        }
예제 #30
0
        public async Task <ActionResult> Create(CreateGroupModel model)
        {
            if (ModelState.IsValid)
            {
                model.UserInSystem = User.Identity.Name;
                model.Group        = true;
                var group = mapper.Map <CreateGroupModel, GroupVisitorDTO>(model);

                var result = await _groupService.Create(group);

                if (result.Succedeed)
                {
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", result.Message);
                }
            }
            ViewBag.Genders       = Gender();
            ViewBag.CheckPoints   = CheckPoints();
            ViewBag.Nationalities = Nationalities();
            return(View(model));
        }