Example #1
0
        public IHttpActionResult CreateGroup(CreateGroupViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            bool groupExists = this.groupService.GroupExists(viewModel.GroupName);

            if (groupExists)
            {
                return(Conflict());
            }

            var group = Mapper.Map <Group>(viewModel);

            group.CreatorId = User.Identity.GetUserId();
            group.CreatedAt = DateTime.Now;

            this.groupService.AddGroup(group);
            var result = new CreateGroupResultModel
            {
                GroupId   = group.GroupId,
                GroupName = group.Name,
                CreatedAt = group.CreatedAt,
                CreatedBy = User.Identity.GetUserName(),
            };

            return(Created("", result)); // TODO: url
        }
Example #2
0
        public PartialViewResult _Create(CreateGroupViewModel model)
        {
            string userId = User.Identity.GetUserId();

            if (!ModelState.IsValid)
            {
                return(PartialView("_Create", model));
            }
            var useraccount = new UserAccount();

            if (!model.Members.IsNullOrWhiteSpace())
            {
                var userExist = useraccount.UsersExist(model.Members);
                if (!userExist)
                {
                    TempData["errorMessage"] = "Invalid user name!";
                    return(PartialView("_Create", model));
                }
            }
            var groupcom = new GroupCommunication();

            if (groupcom.GroupExist(model.GroupName))
            {
                TempData["errorMessage"] = "This group name is already taken!";
                return(PartialView("_Create", model));
            }

            string members = model.Members + ";" + User.Identity.Name;

            groupcom.SaveNewGroup(userId, model.GroupName, model.Description, members, DateTime.Now);
            ModelState.Clear();
            TempData["successMessage"] = "This group is Created!";

            return(PartialView("_Create"));
        }
Example #3
0
        public ActionResult Create(CreateGroupViewModel group)
        {
            Request.ThrowIfDifferentReferrer();

            if (ModelState.IsValid)
            {
                string groupName = group.Name;
                bool   exists    = _database.Groups
                                   .FilterByName(groupName)
                                   .Any();

                if (exists == false)
                {
                    var command = new CreateGroupCommand()
                    {
                        Name = group.Name
                    };
                    _dispatcher.Dispatch(command);

                    var createdGroup = _database.Groups
                                       .FilterByName(groupName)
                                       .SingleOrDefault();

                    return(RedirectToAction(nameof(GroupNodeController.Index), GroupNodeController.ControllerName, new { groupId = createdGroup.Id }));
                }

                ModelState.AddModelError(nameof(group.Name), "A group with this name already exists.");
            }

            return(View(group));
        }
Example #4
0
        public ActionResult Create(CreateGroupViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    this.Current.Services.GroupService.CreateGroup(
                        new Group
                    {
                        CreateDateUtc = DateTime.UtcNow,
                        CreateUserId  = Current.UserId.Value,
                        Description   = model.Description,
                        Name          = model.Name
                    });

                    return(this.JsonSuccess(
                               data: null,
                               message: string.Format(ValidationResources.Group_Create_Success, model.Name),
                               returnUrl: Routes.IndexGroups.GetActionLink(Url)));
                }

                return(this.JsonError(data: null, message: ValidationResources.Generic_ModelState_Error));
            }
            catch (Exception e)
            {
                this.HandleError(e);
                return(this.JsonError(data: null, message: ValidationResources.Generic_Error));
            }
        }
Example #5
0
        public IActionResult Create(CreateGroupViewModel model)
        {
            if (!ModelState.IsValid)
            {
                model.Items = PopulateIndestries();
                return(View(model));
            }

            if (model.IndustryId == "-1")
            {
                ModelState.AddModelError(string.Empty, "必须选择行业");
            }

            if (IsGroupNameExists(model.GroupName) == false)
            {
                ModelState.AddModelError(string.Empty, "集团名称已经存在");
            }

            if (ModelState.ErrorCount > 0)
            {
                model.Items = PopulateIndestries();
                return(View(model));
            }

            var dbGroup = new DD.Electricity.Cloud.Domain.Entities.Headquarter.Group();

            dbGroup.Name       = model.GroupName;
            dbGroup.IndustryId = int.Parse(model.IndustryId);

            _hdDbContext.Groups.Add(dbGroup);
            _hdDbContext.SaveChanges();

            return(RedirectToAction(nameof(Index)));
        }
        public IActionResult Create(CreateGroupViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var authGroup = new AuthGroup
            {
                Name       = model.Name,
                Author     = User.Identity.Name,
                ModifiedBy = User.Identity.Name
            };

            try
            {
                Context.AuthGroups.Add(authGroup);
                Context.SaveChanges();
                return(RedirectToAction(nameof(Index)));
            }
            catch (DbUpdateException)
            {
                ModelState.AddModelError(string.Empty, "The group already exists.");
            }

            return(View(model));
        }
Example #7
0
        public IHttpActionResult Leave(int groupId)
        {
            var group = this.Data.Groups.Find(groupId);

            var currentUserId = this.User.Identity.GetUserId();
            var currentUser   = this.Data.Users.FirstOrDefault(u => u.Id == currentUserId);

            if (currentUser == null)
            {
                return(this.BadRequest("Invalid user token! Please login again!"));
            }

            if (group == null)
            {
                return(this.NotFound());
            }

            var member = group.Members.FirstOrDefault(m => m.Id == currentUserId);

            if (member == null)
            {
                return(this.BadRequest("You are not a member of this group."));
            }

            group.Members.Remove(member);
            this.Data.SaveChanges();

            return(this.Ok(CreateGroupViewModel.CreateGroupPreview(currentUser, group)));
        }
Example #8
0
        public IHttpActionResult CreateGroup([FromBody] CreateGroupViewModel groupModel)
        {
            if (groupModel == null || !ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var currentUser = this._usersService.GetUserById(this._currentUserId);

            try
            {
                var group        = this._groupsService.CreateGroup(groupModel.Name, currentUser);
                var participants = group.Users.Select(
                    u => new UserShortViewModel(u.UserName, u.DisplayName, u.PhoneNumber, u.Email))
                                   .ToList();

                var model = new GroupViewModel(group.Name, group.Owner.DisplayName, participants);

                return(Content(HttpStatusCode.Created, model));
            }
            catch (Exception)
            {
                return(Content(HttpStatusCode.Conflict, "The name should be unique!"));
            }
        }
 public CreateGroupPage(INavigation navigation)
 {
     InitializeComponent();
     BindingContext       = viewModel = new CreateGroupViewModel(navigation);
     viewModel.ButtonText = "Создать группу";
     Submit.Clicked      += CreateGroup;
 }
 public CreateGroupPage(CreateGroupViewModel createGroupViewModel, IInternetConnectionChecker internetConnectionChecker)
 {
     InitializeComponent();
     _createGroupViewModel      = createGroupViewModel;
     _internetConnectionChecker = internetConnectionChecker;
     BindingContext             = _createGroupViewModel;
 }
Example #11
0
        public IActionResult CreateGroup(CreateGroupViewModel viewModel)
        {
            System.Console.WriteLine("!!!!!!!!!!!!!!!!!!!!!!!!!!");
            if (HttpContext.Session.GetInt32("InSession") != null)
            {
                System.Console.WriteLine("@@@@@@@@@@@@@@@@@@@@@@@@@");
                if (ModelState.IsValid)
                {
                    System.Console.WriteLine("###########################");
                    Group newGroup = viewModel.newGroup;
                    newGroup.Leader = dbContext.Users
                                      .FirstOrDefault(u => u.UserId == HttpContext.Session.GetInt32("InSession"));
                    viewModel.currentUser = dbContext.Users
                                            .FirstOrDefault(u => u.UserId == HttpContext.Session.GetInt32("InSession"));
                    newGroup.School = dbContext.Schools
                                      .FirstOrDefault(s => s.SchoolId == viewModel.currentUser.SchoolId);

                    dbContext.Add(newGroup);
                    dbContext.SaveChanges();
                    return(RedirectToAction("Dashboard", newGroup));
                }
                System.Console.WriteLine("$$$$$$$$$$$$$$$$$$$$$$$$$$$");
                return(View("Create"));
            }
            return(RedirectToAction("Index"));
        }
Example #12
0
        public async Task CreateGroup(CreateGroupViewModel model)
        {
            var groupData = new Data.Group();

            groupData.Name      = model.Name;
            groupData.Type      = model.Type;
            groupData.ExtraType = model.ExtraType;
            DefaultDbContext.Instance.Group.Add(groupData);
            DefaultDbContext.Instance.SaveChanges();

            var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
            var user   = DefaultDbContext.Instance.Users.FirstOrDefault(x => x.Id == userId);


            var createGroupMessage = new CreateGroupMessage
            {
                UserName       = user?.UserName,
                GroupName      = model.Name,
                SocialClub     = model.socialclub,
                GroupExtraType = model.ExtraType,
                GroupType      = model.Type
            };

            using (var client = new HttpClient())
            {
                var content  = new StringContent(JsonConvert.SerializeObject(createGroupMessage), Encoding.UTF8, "application/json");
                var response = await client.PostAsync("http://localhost:3001/CreateGroup", content);

                var responseString = await response.Content.ReadAsStringAsync();
            }
        }
Example #13
0
        public IHttpActionResult GetGroupsForUser([FromUri] string username)
        {
            var user = this.Data.Users.FirstOrDefault(u => u.UserName == username);

            if (user == null)
            {
                return(this.NotFound());
            }

            var userId = user.Id;

            var groupsWhereMember = user.Groups
                                    .Select(g => CreateGroupViewModel.CreateGroupPreview(user, g))
                                    .ToList();

            var groupsWhereOwner = this.Data.Groups
                                   .Where(g => g.Owner.Id == userId)
                                   .ToList()
                                   .Select(g => CreateGroupViewModel.CreateGroupPreview(user, g))
                                   .ToList();

            var totalGroups = groupsWhereMember.Union(groupsWhereOwner);

            return(this.Ok(totalGroups));
        }
        public DoctrinaGroup CreateGroup(CreateGroupViewModel model, string ownerId)
        {
            DoctrinaGroup result = new DoctrinaGroup
            {
                Name = model.Name
            };

            _db.Add <DoctrinaGroup>(result);
            _db.SaveChanges();

            _db.Entry(result).GetDatabaseValues();

            DoctrinaUserDoctrinaGroup newUserGroup = new DoctrinaUserDoctrinaGroup
            {
                DoctrinaGroupId  = result.Id,
                DoctrinaUserId   = ownerId,
                IsAdmin          = true,
                IsInvitePending  = false,
                IsRequestPending = false,
            };

            _db.Add <DoctrinaUserDoctrinaGroup>(newUserGroup);
            _db.SaveChanges();

            string folderPath = Path.Combine(_hostingEnvironment.WebRootPath, "DynamicResources/groups", result.Id);

            Directory.CreateDirectory(folderPath);

            return(result);
        }
Example #15
0
        public CreateGroupResponseViewModel CreateGroup(CreateGroupViewModel createGroupViewModel)
        {
            var newGroup = new Group
            {
                Name        = createGroupViewModel.Name,
                Description = createGroupViewModel.Description
            };

            if (createGroupViewModel.GroupProfiles != null)
            {
                foreach (var profile in createGroupViewModel.GroupProfiles)
                {
                    newGroup.GroupProfiles.Add(new GroupProfile
                    {
                        IsAdmin   = profile.IsAdmin,
                        ProfileId = new Guid(profile.ProfileId)
                    });
                }
            }

            _groupService.InsertGroup(newGroup);

            return(new CreateGroupResponseViewModel
            {
                CreatedGroup = _groupService.GetGroupById(newGroup.Id)
            });
        }
Example #16
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));
        }
Example #17
0
        public ActionResult Create()
        {
            var viewModel = new CreateGroupViewModel();

            viewModel.IsActive = true;
            return(View(viewModel));
        }
 private void VerifyIfGroupIsNotWithUserItself(Contact currentContact, CreateGroupViewModel group)
 {
     if (group.IsOneToOne && group.Participants.Count == 1 &&
         string.Equals(group.Participants[0].Email, currentContact.Email, StringComparison.OrdinalIgnoreCase))
     {
         throw new Exception("Creating chat with yourself is not supported");
     }
 }
 public CreateGroupPage(INavigation navigation, GroupModel group)
 {
     InitializeComponent();
     BindingContext       = viewModel = new CreateGroupViewModel(navigation);
     viewModel.Group      = group;
     viewModel.ButtonText = "Редактировать группу";
     Submit.Clicked      += EditGroup;
 }
        public async Task <IActionResult> Index()
        {
            var viewModel = new CreateGroupViewModel();

            viewModel.GroupTypes = await _groupOrchestrator.ListGroupTypesAsync();

            return(View(viewModel));
        }
Example #21
0
 public async Task <IActionResult> PostAsync([FromBody] CreateGroupViewModel group)
 {
     if (ModelState.IsValid)
     {
         return(Created(nameof(GetByIdAsync), await _groupService.CreateGroupAsync(group)));
     }
     return(BadRequest(ModelState));
 }
Example #22
0
        ///// <summary>
        ///// 用户主动退出群组
        ///// </summary>
        //private void LogoutGroup()
        //{
        //    CloudRequestFactory rf = new CloudRequestFactory();
        //    bool retData = rf.LogoutGroup("sandboxapp.cloopen.com", "8883", "a4041498e56e11e389eed89d672b9690", "e905191387cb8098309b03efd622d7b0", "g8014706989095");
        //    Response.Write(retData);

        //}

        ///// <summary>
        ///// 群主拉人
        ///// </summary>
        //private void InviteJoinGroup()
        //{
        //    CloudRequestFactory rf = new CloudRequestFactory();
        //    List<string> list = new List<string>();
        //    list.Add("80147000000133");
        //    //bool retData = rf.InviteJoinGroup("sandboxapp.cloopen.com", "8883", "5663f9ffe57111e389eed89d672b9690", "4dff67097723e24776da1f5ac0428ed7", "g8014706989095", list, "", "1", "群组管理员邀请用户加入群组");
        //    //Response.Write(retData);
        //}

        ///// <summary>
        ///// 用户申请加入群组
        ///// </summary>
        //private void JoinGroup()
        //{
        //    CloudRequestFactory rf = new CloudRequestFactory();
        //    bool retData = rf.JoinGroup("sandboxapp.cloopen.com", "8883", "a4041498e56e11e389eed89d672b9690", "e905191387cb8098309b03efd622d7b0", "g8014706989095", "相互学习1");
        //    Response.Write(retData);
        //}

        /// <summary>
        /// 创建群组
        /// </summary>
        private void CreateGroup()
        {
            CloudRequestFactory  rf      = new CloudRequestFactory();
            CreateGroupViewModel retData = rf.CreateGroup("sandboxapp.cloopen.com", "8883", "5663f9ffe57111e389eed89d672b9690", "4dff67097723e24776da1f5ac0428ed7", "企信32", "0", "0", "大家好。。。。");

            // string jsonData = getDictionaryData(retData);
            Response.Write(retData);
        }
Example #23
0
        public async Task <ActionResult> ShowFormForAddGroup(int id)
        {
            CreateGroupViewModel createGroupViewModel = new CreateGroupViewModel();

            createGroupViewModel.BranchId = id;
            createGroupViewModel.Users    = new SelectList(_userManager.Users.ToList(), "Id", "Email");
            return(PartialView("_AddGroupForm", createGroupViewModel));
        }
 public async Task <JsonResult> CreateGroup([Required] CreateGroupViewModel model)
 {
     if (!ModelState.IsValid)
     {
         return(JsonModelStateErrors());
     }
     return(await JsonAsync(_groupService.CreateGroupAsync(model)));
 }
Example #25
0
 public ActionResult AddGroup()
 {
     if (Session["Username"] != null)
     {
         CreateGroupViewModel group = new CreateGroupViewModel();
         return(View(group));
     }
     return(RedirectToAction("Login", "Player"));
 }
Example #26
0
        public IActionResult Create()
        {
            var model = new CreateGroupViewModel();

            model.Items = PopulateIndestries();


            return(View(model));
        }
        //
        // GET: /Lesson/Create

        public ActionResult Create(int lessonId)
        {
            var response = new CreateGroupViewModel
            {
                LessonId = lessonId
            };

            return(View(response));
        }
Example #28
0
        public IActionResult Create()
        {
            var model = new CreateGroupViewModel
            {
                Faculties = _facultyRepository.GetList()
            };

            return(View(model));
        }
Example #29
0
        public async Task <GroupViewModel> CreateGroupAsync(CreateGroupViewModel createGroupViewModel)
        {
            var createdGroup = await _repository.Add(new Group
            {
                Name = createGroupViewModel.Name
            });

            return(MapGroupToGroupViewModel(createdGroup));
        }
        /// <summary>
        /// Used to create a group for the user.
        /// </summary>
        /// <param name="closeAfter">If the page should close after we are done.</param>
        /// <returns></returns>
        public IActionResult Create(bool closeAfter)
        {
            var model = new CreateGroupViewModel();

            model.AccessTypes = DatabaseConnector.Get <AccessTypes>();
            model.Users       = DatabaseConnector.GetWhere <Users>("OrganisationID=" + OrganisationHelper.GetOrganisationID(HttpContext.Session));
            model.CloseAfter  = closeAfter;

            return(View(model));
        }
        public ActionResult Create(CreateGroupViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    ClanGroup newGroup = new ClanGroup();

                    int leaderId = 0;
                    int.TryParse(model.GroupLeaderId, out leaderId);

                    newGroup.name = model.GroupName;
                    newGroup.groupLeaderId = leaderId;
                    newGroup.clanId = model.ClanId;

                    ClanGroupManager.Insert(newGroup);

                    ClanUser groupLeader = ClanUserManager.SelectByClanUserId(leaderId);
                    groupLeader.clanGroupId = newGroup.id;

                    ClanUserManager.Update(groupLeader);

                    if(model.GroupMemberIds != null && model.GroupMemberIds.Count > 0)
                    {
                        foreach(var memberId in model.GroupMemberIds)
                        {
                            int id = 0;
                            int.TryParse(memberId, out id);

                            ClanUser member = ClanUserManager.SelectByClanUserId(id);
                            member.clanGroupId = newGroup.id;

                            ClanUserManager.Update(member);
                        }
                    }
                }
            }
            catch
            {
                int? clanId = ClanManager.GetClanId(User.Identity.GetUserId());

                return View(new CreateGroupViewModel((int)clanId));
            }

            return RedirectToAction("EditMode");
        }