public IActionResult NewGroupChatStep1(NewGroupChatStep1ViewModel model)
        {
            ViewData["Id"] = model.CreatedBy;

            string name = (model.Name == null || model.Name.Trim() == "") ? "Group" : model.Name;

            GroupChat groupChat = new GroupChat
            {
                CreatedBy = model.CreatedBy,
                Title     = model.Name
            };

            //create new chat
            repository.EditGroupChat(groupChat);

            if (model.Name == null || model.Name.Trim() == "")
            {
                groupChat.Title = "GroupChat" + groupChat.ChatId;
                repository.EditGroupChat(groupChat);
            }

            if (model.Photo != null)
            {
                AddGroupChatPhoto(groupChat.ChatId, model.Photo);
            }

            return(RedirectToAction("NewGroupChatStep2", new
            {
                id = model.CreatedBy,
                groupChatId = groupChat.ChatId
            }));
        }
        public async Task <IActionResult> NewGroup(NewGroupViewModel model)
        {
            ViewData["Id"] = model.CreatedById;

            AppUser user = await userManager.FindByIdAsync(model.CreatedById);

            if (user != null)
            {
                string status = (model.Status == true) ? "Public" : "Private";

                Group newGroup = new Group
                {
                    Name        = model.Name,
                    Description = model.Description,
                    CreatedBy   = user,
                    CompanyName = user.CompanyName,
                    Status      = status
                };

                int groupId = repository.SaveGroup(newGroup);
                repository.AddUserToGroup(user.Id, groupId);

                //if photo exists
                if (model.ProfilePhoto != null)
                {
                    AddGroupPhoto(groupId, model.ProfilePhoto);
                }

                //create chat
                if (model.CreateChat == true)
                {
                    GroupChat groupChat = new GroupChat
                    {
                        Title         = model.Name,
                        Status        = status,
                        CreatedBy     = user.Id,
                        ChatPhotoPath = "Groups/" + repository.Groups
                                        .FirstOrDefault(g => g.GroupId == newGroup.GroupId).GroupPhotoPath
                    };
                    repository.EditGroupChat(groupChat);

                    //add admin to chat
                    repository.AddUserToGroupChat(groupChat.ChatId, user.Id);

                    newGroup.GroupChatId = groupChat.ChatId;
                    repository.SaveGroup(newGroup);
                }

                return(RedirectToAction("NewGroupStep2", new { id = model.CreatedById, groupId }));
            }

            return(RedirectToAction("Error", "UserNotFound"));
        }