public GroupDetailViewModel GetDetail(int id)
        {
            var sqlScript  = @"
SELECT [g].[Id], [g].[Name], [g].[Created]
FROM [dbo].[Group] [g]
WHERE [Id] = @id

SELECT [u].[Name]
FROM [dbo].[UserGroup] [ug]
    LEFT JOIN [dbo].[User] [u]
              ON [u].[Id] = [ug].[UserId]
WHERE [ug].[GroupId] = @id

SELECT [r].[Name]
FROM [dbo].[GroupRole] [gr]
    LEFT JOIN [dbo].[Role] [r]
              ON [gr].[RoleId] = [r].[Id]
WHERE [gr].[GroupId] = @id
";
            var parameters = new DynamicParameters();

            parameters.Add("id", id, DbType.Int32);
            var result = new GroupDetailViewModel();

            using (var conn = new SqlConnection(ConnectionString))
            {
                var reader = conn.QueryMultiple(sqlScript, parameters);
                result.Group     = reader.Read <Group>().FirstOrDefault();
                result.UserNames = reader.Read <string>().ToArray();
                result.RoleNames = reader.Read <string>().ToArray();
            }

            return(result);
        }
Ejemplo n.º 2
0
        public ActionResult ShowGroupDetail(int id, string currentUser)
        {
            var groupService = this.Service <IGroupService>();

            var groupMemberService = this.Service <IGroupMemberService>();

            ResponseModel <GroupDetailViewModel> response = null;

            try
            {
                Group group = groupService.FindGroupById(id);

                GroupDetailViewModel result = Mapper.Map <GroupDetailViewModel>(group);

                result.IsAdmin = groupMemberService.CheckAdmin(currentUser, result.Id);

                result.IsMember = groupMemberService.CheckMember(currentUser, result.Id);

                response = new ResponseModel <GroupDetailViewModel>(true, "Thông tin nhóm:", null, result);
            }
            catch (Exception)
            {
                response = ResponseModel <GroupDetailViewModel> .CreateErrorResponse("Tải thông tin thất bại!", systemError);
            }

            return(Json(response));
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> GovernanceChangeHistoryAsync(int id, int skip = 0, string sortBy = null)
        {
            var result = await _groupReadService.GetAsync(id, User);

            if (result.ReturnValue == null)
            {
                return(HttpNotFound());
            }
            var model = result.ReturnValue;

            var viewModel = new GroupDetailViewModel
            {
                Group              = model,
                GroupTypeName      = model.GroupTypeId.HasValue ? await _lookup.GetNameAsync(() => model.GroupTypeId) : null,
                LocalAuthorityName = await _lookup.GetNameAsync(() => model.LocalAuthorityId),
                GroupStatusName    = await _lookup.GetNameAsync(() => model.StatusId, "Group"),
                Address            = model.GroupTypeId.OneOfThese(GT.SingleacademyTrust, GT.MultiacademyTrust, GT.ChildrensCentresGroup) ? model.Address.ToString() : null,
                IsUserLoggedOn     = User.Identity.IsAuthenticated,
                GroupTypeId        = model.GroupTypeId ?? -1,
                IsClosed           = model.StatusId == (int)GS.Closed || model.StatusId == (int)GS.CreatedInError,
                IsClosedInError    = model.StatusId == (int)GS.CreatedInError,
                CloseDate          = model.ClosedDate,
                ChangeHistory      = await _groupReadService.GetGovernanceChangeHistoryAsync(id, skip, 100, sortBy, User)
            };

            return(View("GovernanceChangeHistory", viewModel));
        }
Ejemplo n.º 4
0
        public async Task <ActionResult> Details(int id, string searchQueryString = "", eLookupSearchSource searchSource = eLookupSearchSource.Groups, int skip = 0, string sortBy = null, bool saved = false)
        {
            ViewBag.ShowSaved = saved;

            var model = (await _groupReadService.GetAsync(id, User)).GetResult();

            var viewModel = new GroupDetailViewModel
            {
                SearchQueryString     = searchQueryString,
                SearchSource          = searchSource,
                CanUserEdit           = await _groupReadService.CanEditAsync(id, User),
                CanUserEditGovernance = await _groupReadService.CanEditGovernanceAsync(id, User),
                Group              = model,
                GroupTypeName      = model.GroupTypeId.HasValue ? await _lookup.GetNameAsync(() => model.GroupTypeId) : null,
                LocalAuthorityName = model.LocalAuthorityId.HasValue ? await _lookup.GetNameAsync(() => model.LocalAuthorityId) : null,
                GroupStatusName    = model.StatusId.HasValue ? await _lookup.GetNameAsync(() => model.StatusId, "Group") : null,
                Address            = model.GroupTypeId.OneOfThese(GT.SingleacademyTrust, GT.MultiacademyTrust, GT.ChildrensCentresGroup) ? model.Address.ToString() : null,
                IsUserLoggedOn     = User.Identity.IsAuthenticated,
                GroupTypeId        = model.GroupTypeId ?? -1,
                IsClosed           = model.StatusId == (int)eLookupGroupStatus.Closed || model.StatusId == (int)eLookupGroupStatus.CreatedInError,
                IsClosedInError    = model.StatusId == (int)eLookupGroupStatus.CreatedInError,
                CloseDate          = model.ClosedDate
            };

            if (viewModel.IsUserLoggedOn)
            {
                viewModel.ChangeHistory = await _groupReadService.GetChangeHistoryAsync(id, skip, 100, sortBy.Clean() ?? "requestedDateUtc-desc", User);
            }

            await PopulateEstablishmentList(viewModel.Establishments, model.GroupUId.Value, true);

            return(View(viewModel));
        }
Ejemplo n.º 5
0
        public ActionResult Edit(string id)
        {
            try
            {
                //初始化物件
                var m = new GroupDetailViewModel();

                //取得群組資料
                var dtGroup   = GroupDataAccess.GetGroupList(id, null, new Pages());
                var listGroup = Util.ToList <GroupDetailViewModel>(dtGroup);
                m = listGroup[0];

                //取得排序過的選單清單
                var dtMenu = GroupDataAccess.GetGroupMenuAuth(id);
                m.AuthList = Util.ToList <MenuAuth>(dtMenu);

                //取得群組底下的使用者清單
                var dtGroupUser = GroupDataAccess.GetGroupUser(id);
                m.GroupUserItems = Util.ToList <GroupUserItem>(dtGroupUser);

                return(View("Detail", m));
            }
            catch
            {
                return(RedirectToAction("Error", "Home"));
            }
        }
Ejemplo n.º 6
0
        private GroupDetailWindow()
        {
            model            = new GroupDetailViewModel();
            this.DataContext = model;
            model.Window     = this;

            this.AddModel(model);

            InitializeComponent();
        }
Ejemplo n.º 7
0
 public GroupDetailWindow(GroupDetailViewModel vmGroup = null)
     : this()
 {
     if (vmGroup != null)
     {
         vmGroup.CopyTo(model);
     }
     base.Title           = model.IsNew ? "新增组织" : "修改组织";
     txtGpCode.IsReadOnly = model.groupdata.gp_code.IsNotEmpty();
 }
Ejemplo n.º 8
0
        public async Task<IActionResult> EditGroupDetail(GroupDetailViewModel model)
        {
            if (ModelState.IsValid)
            {
                var groupDetailEntity = await _converterHelper.ToGroupDetailEntityAsync(model, false);
                _context.Update(groupDetailEntity);
                await _context.SaveChangesAsync();
                return RedirectToAction($"{nameof(DetailsGroup)}/{model.GroupId}");
            }

            return View(model);
        }
Ejemplo n.º 9
0
        public GroupDetailPage(GroupDetailViewModel viewModel)
        {
            InitializeComponent();
            BindingContext = this.viewModel = viewModel;

            this.viewModel.OnFinished += OnFinished;

            viewModel.OnNavigateToDetails = async(detailsViewModel) =>
            {
                await Navigation.PushAsync(new DetailPage(detailsViewModel));
            };
        }
Ejemplo n.º 10
0
        public async Task <IActionResult> EditGroupDetail(GroupDetailViewModel model)
        {
            if (ModelState.IsValid)
            {
                GroupDetailEntity groupDetailEntity = await contenedorTrabajo.Converter.ToGroupDetailEntityAsync(model, false);

                contenedorTrabajo.Tournament.UpdateDetailGroupEntity(groupDetailEntity);
                contenedorTrabajo.Save();
                return(RedirectToAction("DetailsGroup", "Tournaments", new { id = model.GroupId }));
            }

            return(View(model));
        }
Ejemplo n.º 11
0
        public async Task <IActionResult> EditGroupDetail(GroupDetailViewModel model)
        {
            if (ModelState.IsValid)
            {
                GroupDetailEntity groupDetailEntity = await _converterHelper.ToGroupDetailEntityAsync(model, false);

                _context.Update(groupDetailEntity);
                await _context.SaveChangesAsync();

                return(RedirectToAction("DetailsGroup", new { id = model.GroupId }));
            }

            return(View(model));
        }
Ejemplo n.º 12
0
        public async Task<IActionResult> AddGroupDetail(GroupDetailViewModel model)
        {
            if (ModelState.IsValid)
            {
                var groupDetailEntity = await _converterHelper.ToGroupDetailEntityAsync(model, true);
                _context.Add(groupDetailEntity);
                await _context.SaveChangesAsync();
                return RedirectToAction($"{nameof(DetailsGroup)}/{model.GroupId}");
            }
            model.Group = await _context.Groups.FindAsync(model.GroupId);
            model.Teams = _combosHelper.GetComboTeams();
            return View(model);

        }
        public GroupDetailViewModel GetDetail(int id)
        {
            var sqlScript = @"
SELECT [g].[Id], [g].[Name], [g].[Created]
FROM [dbo].[Group] [g]
WHERE [Id] = @id

SELECT [u].[Name]
FROM [dbo].[UserGroup] [ug]
    LEFT JOIN [dbo].[User] [u]
              ON [u].[Id] = [ug].[UserId]
WHERE [ug].[GroupId] = @id

SELECT [r].[Name]
FROM [dbo].[GroupRole] [gr]
    LEFT JOIN [dbo].[Role] [r]
              ON [gr].[RoleId] = [r].[Id]
WHERE [gr].[GroupId] = @id
";
            var result    = new GroupDetailViewModel();

            using (var dbContext = DbContextFactory.CreateEfDbContext())
            {
                var command = dbContext.Database.Connection.CreateCommand();
                command.CommandText = sqlScript;
                command.CommandType = CommandType.Text;
                command.Parameters.Clear();

                var parameter = new SqlParameter(parameterName: "id", value: id)
                {
                    SqlDbType = SqlDbType.Int
                };
                command.Parameters.Add(parameter);

                dbContext.Database.Connection.Open();
                using (var reader = command.ExecuteReader())
                {
                    var objectContextAdapter = ((IObjectContextAdapter)dbContext).ObjectContext;

                    result.Group = objectContextAdapter.Translate <Group>(reader).FirstOrDefault();
                    reader.NextResult();
                    result.UserNames = objectContextAdapter.Translate <string>(reader).ToArray();
                    reader.NextResult();
                    result.RoleNames = objectContextAdapter.Translate <string>(reader).ToArray();
                }
            }

            return(result);
        }
Ejemplo n.º 14
0
 public async Task <GroupDetailEntity> ToGroupDetailEntityAsync(GroupDetailViewModel model, bool isNew)
 {
     return(new GroupDetailEntity
     {
         GoalsAgainst = model.GoalsAgainst,
         GoalsFor = model.GoalsFor,
         Group = await _context.Groups.FindAsync(model.GroupId),
         Id = isNew ? 0 : model.Id,
         MatchesLost = model.MatchesLost,
         MatchesPlayed = model.MatchesPlayed,
         MatchesTied = model.MatchesTied,
         MatchesWon = model.MatchesWon,
         Team = await _context.Teams.FindAsync(model.TeamId)
     });
 }
Ejemplo n.º 15
0
        public async Task <IActionResult> AddGroupDetail(GroupDetailViewModel model)
        {
            if (ModelState.IsValid)
            {
                GroupDetailEntity groupDetailEntity = await contenedorTrabajo.Converter.ToGroupDetailEntityAsync(model, true);

                contenedorTrabajo.Tournament.AddDetailGroupEntity(groupDetailEntity);
                contenedorTrabajo.Save();
                return(RedirectToAction("DetailsGroup", "Tournaments", new { id = model.GroupId }));
            }

            model.Group = await contenedorTrabajo.Tournament.GetGroup(model.GroupId);

            model.Teams = contenedorTrabajo.Combos.GetComboTeams();
            return(View(model));
        }
Ejemplo n.º 16
0
        public JsonResult Save(GroupDetailViewModel m)
        {
            Result r = new Result();

            try
            {
                GroupDataAccess.SaveGroupInfo(m);
                r.Set(ResultCode.Success, "作業成功");
            }
            catch (Exception e)
            {
                r.Set(ResultCode.Error, e.Message);
            }

            return(Json(r, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 17
0
        public async Task <IActionResult> AddGroupDetail(GroupDetailViewModel model)
        {
            if (ModelState.IsValid)
            {
                GroupDetailEntity groupDetailEntity = await _converterHelper.ToGroupDetailEntityAsync(model, true);

                _context.Add(groupDetailEntity);
                await _context.SaveChangesAsync();

                return(RedirectToAction("DetailsGroup", new { id = model.GroupId }));
            }

            model.Group = await _context.Groups.FindAsync(model.GroupId);

            model.Teams = _combosHelper.GetComboTeams();
            return(View(model));
        }
Ejemplo n.º 18
0
        public async Task <IActionResult> AddGroupDetail(GroupDetailViewModel model)
        {
            if (ModelState.IsValid)
            {
                var groupDetailEntity = await _converterHelper.ToGroupDetailEntityAsync(model, true);

                _context.Add(groupDetailEntity);
                await _context.SaveChangesAsync();

                return(RedirectToAction($"{nameof(DetailsGroup)}/{model.GroupId}"));
            }
            //Aqui se hace cuando el modeo falla para que no se pierda el combo
            model.Group = await _context.Groups.FindAsync(model.GroupId);

            model.Teams = _combosHelper.GetComboTeams();
            return(View(model));
        }
Ejemplo n.º 19
0
        public ActionResult Add(string id)
        {
            try
            {
                //初始化物件
                var m = new GroupDetailViewModel();

                //取得排序過的選單清單
                var dtMenu = GroupDataAccess.GetGroupMenuAuth("0");
                m.AuthList = Util.ToList <MenuAuth>(dtMenu);

                return(View("Detail", m));
            }
            catch
            {
                return(RedirectToAction("Error", "Home"));
            }
        }
Ejemplo n.º 20
0
        public async Task <IActionResult> EditGroupDetail(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            GroupDetailEntity groupDetailEntity = await _dataContext.GroupDetails.Include(gd => gd.Group).Include(gd => gd.Team).FirstOrDefaultAsync(gd => gd.Id == id);

            if (groupDetailEntity == null)
            {
                return(NotFound());
            }

            GroupDetailViewModel model = _converterHelper.ToGroupDetailViewModel(groupDetailEntity);

            return(View(model));
        }
Ejemplo n.º 21
0
        public async Task <IActionResult> EditGroupDetail(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            GroupDetailEntity groupDetailEntity = await contenedorTrabajo.Tournament.GetGroupDetailEntity(id.Value);

            if (groupDetailEntity == null)
            {
                return(NotFound());
            }

            GroupDetailViewModel model = contenedorTrabajo.Converter.ToGroupDetailViewModel(groupDetailEntity);

            return(View(model));
        }
Ejemplo n.º 22
0
        public ActionResult UpdateGroup(GroupDetailViewModel model)
        {
            var result      = new AjaxOperationResult();
            var groupSerive = this.Service <IGroupService>();
            var groupId     = model.Id;
            var group       = groupSerive.FirstOrDefaultActive(p => p.Id == groupId);

            if (group != null)
            {
                group.StartTime   = model.StartTime;
                group.EndTime     = model.EndTime;
                group.PlaceId     = model.PlaceId;
                group.Name        = model.Name;
                group.Description = model.Description;
                group.SportId     = model.SportId;
                if (model.Days != null)
                {
                    string[] days      = model.Days.Split(',');
                    int      repeatDay = 0;
                    for (int i = 0; i < days.Length; i++)
                    {
                        if (days[i].Length > 0)
                        {
                            int mark = 1 << Int16.Parse(days[i]);
                            repeatDay = repeatDay | mark;
                        }
                    }
                    group.AvailableDays = repeatDay;
                }
                else
                {
                    group.AvailableDays = null;
                }
                groupSerive.Update(group);
                groupSerive.Save();
                result.Succeed = true;
            }
            else
            {
                result.Succeed = false;
            }
            return(Json(result));
        }
Ejemplo n.º 23
0
        public ActionResult EditGroup(int id)
        {
            var   groupService         = this.Service <IGroupService>();
            var   _sportService        = this.Service <ISportService>();
            var   placeService         = this.Service <IPlaceService>();
            Group group                = groupService.FirstOrDefaultActive(p => p.Id == id);
            GroupDetailViewModel model = Mapper.Map <GroupDetailViewModel>(group);
            var sports = _sportService.GetActive()
                         .Select(s => new SelectListItem
            {
                Text  = s.Name,
                Value = s.Id.ToString()
            }).OrderBy(s => s.Value);

            ViewBag.Sport = sports;
            var places = placeService.GetActive()
                         .Select(s => new SelectListItem
            {
                Text  = s.Name,
                Value = s.Id.ToString()
            }).OrderBy(s => s.Value);

            ViewBag.Place = places;
            var dayOfWeek = new List <int>();

            if (model.AvailableDays != null)
            {
                var bits = new bool[8];
                for (var i = 7; i >= 0; i--)
                {
                    bits[i] = (model.AvailableDays & (1 << i)) != 0;
                }
                for (var j = 1; j < bits.Length; j++)
                {
                    if (bits[j])
                    {
                        dayOfWeek.Add(j);
                    }
                }
            }
            ViewBag.availableDayOfWeek = dayOfWeek;
            return(this.PartialView(model));
        }
Ejemplo n.º 24
0
        public async Task <IActionResult> EditGroupDetail(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            GroupDetailEntity entity = await _context.GroupDetails.Include(t => t.Group)
                                       .Include(t => t.Team)
                                       .FirstOrDefaultAsync(t => t.Id == id);

            if (entity == null)
            {
                return(NotFound());
            }

            GroupDetailViewModel model = _converter.ToGroupDetailViewModelAsync(entity);

            return(View(model));
        }
Ejemplo n.º 25
0
        // GET: Groups/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Group group = db.Groups.Find(id);
            GroupDetailViewModel model = new GroupDetailViewModel();

            if (group == null)
            {
                return(HttpNotFound());
            }

            model.Id = group.ID;
            //model.IsCreator = group.CreatorID==User.Identity.GetUserId();
            model.Name    = group.Name;
            model.Date    = group.CreatedDate;
            model.Members = group.Receviers.Select(g => g.UserName).ToList();

            return(View(model));
        }
Ejemplo n.º 26
0
        public async Task<IActionResult> AddGroupDetail(int? id)
        {
            if (id == null)
            {
                return NotFound();
            }

            var groupEntity = await _context.Groups.FindAsync(id);
            if (groupEntity == null)
            {
                return NotFound();
            }

            var model = new GroupDetailViewModel
            {
                Group = groupEntity,
                GroupId = groupEntity.Id,
                Teams = _combosHelper.GetComboTeams()
            };

            return View(model);
        }
Ejemplo n.º 27
0
        public ActionResult Edit(string groupId)
        {
            if (groupId.IsNullOrWhiteSpace())
            {
                return(View("Error"));
            }
            int grpId = Int32.Parse(groupId);

            // Get the group
            var groupService = new GroupService(DbContext);
            var grp          = groupService.GetGroupById(grpId);
            var model        = new GroupDetailViewModel()
            {
                AdminId = grp.AdminID,
                GroupId = grp.GroupId,
                Name    = grp.Name,
                Members = new List <UserViewModel>()
            };

            // Get the members of the group
            var userService    = new UserService(DbContext);
            var membersOfGroup = groupService.GetMembersOfGroup(grpId);

            foreach (var id in membersOfGroup)
            {
                var currUser = userService.GetUserById(id);
                if (currUser.Id != User.Identity.GetUserId())
                {
                    model.Members.Add(new UserViewModel()
                    {
                        UserId = currUser.Id,
                        Name   = currUser.Name
                    });
                }
            }

            return(View(model));
        }
Ejemplo n.º 28
0
        public async Task <IActionResult> AddGroupDetail(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            GroupEntity groupEntity = await contenedorTrabajo.Tournament.GetGroup(id.Value);

            if (groupEntity == null)
            {
                return(NotFound());
            }

            GroupDetailViewModel model = new GroupDetailViewModel
            {
                Group   = groupEntity,
                GroupId = groupEntity.Id,
                Teams   = contenedorTrabajo.Combos.GetComboTeams()
            };

            return(View(model));
        }
Ejemplo n.º 29
0
        public async Task <IActionResult> AddGroupDetail(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            GroupEntity entity = await _context.Groups.FindAsync(id);

            if (entity == null)
            {
                return(NotFound());
            }

            GroupDetailViewModel model = new GroupDetailViewModel
            {
                Group   = entity,
                GroupId = entity.Id,
                Teams   = _combo.GetComboTeams()
            };

            return(View(model));
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Admin can view request to be Expert.
        ///
        /// Author: Chris Schwebach
        /// </summary>
        /// <param name="group"></param>
        /// <returns></returns>
        public ActionResult MngExpert()
        {
            int userId = RetrieveUserId();

            GroupManager grMangr = new GroupManager();
            Group        grp     = grMangr.RetrieveGroupByName(WebConfigurationManager.AppSettings["ExpertGroup"]);
            int          groupId = grp.GroupID;

            var viewModel = new GroupDetailViewModel();

            viewModel.Requests = new List <GroupMemberRequestModel>();
            List <GroupRequest> requests = new GroupManager().GetGroupRequests(groupId);

            foreach (GroupRequest request in requests)
            {
                GroupMemberRequestModel requestModel = new GroupMemberRequestModel();
                requestModel.Request   = request;
                requestModel.Requestor = new UserManager().GetUser(request.UserID);
                viewModel.Requests.Add(requestModel);
            }


            return(View(viewModel));
        }
Ejemplo n.º 31
0
        public ActionResult Index(Guid id)
        {
            GroupDto group = readModel.GetGroups().FirstOrDefault(g => g.Id == id);

            if (group != null)
            {
                GroupDetailViewModel model = new GroupDetailViewModel();
                model.Name = group.Name;
                model.Id = group.Id;
                model.Description = group.Description;
                model.Users = group.Members;
                model.Moderators = group.Moderators;

                model.Photos = group.Photos;

                model.Albums = group.Albums;

                model.Privacy = group.Privacy;

                model.LatestAnnouncement = group.Announcements.OrderByDescending(g => g.Time).FirstOrDefault();

                ViewBag.LoggedIn = Session["user"] != null;
                ViewBag.InGroup = ViewBag.LoggedIn ? model.Users.Any(u => u.Username == ((UserDto)Session["user"]).Username) : false;
                ViewBag.IsModerator = ViewBag.InGroup ? group.Moderators.Contains(((UserDto)Session["user"])) : false;
                ViewBag.IsAdmin = ViewBag.InGroup ? group.Admin.Id == ((UserDto)Session["user"]).Id : false;
                ViewBag.RequestPending = ViewBag.LoggedIn ? group.JoinRequests.Contains(((UserDto)Session["user"])) : false;

                return View(model);
            }
            else
                return new HttpNotFoundResult();
        }