public IHttpActionResult Post(TeamPageModel model) { if (!ModelState.IsValid || model == null) { return(Response(new { Success = false, Message = "Invalid data" })); } var teamPage = new TeamPage { Description = model.Description, Name = model.Name, TeamPictureId = model.TeamPictureId, CreatedBy = ApplicationContext.Current.CurrentUser.Id, CreatedOn = DateTime.UtcNow, UpdatedOn = DateTime.UtcNow }; //save to db now _teamPageService.Insert(teamPage); return(RespondSuccess(new { TeamPage = teamPage.ToModel(_mediaService) })); }
public IHttpActionResult Put(TeamPageModel model) { if (!ModelState.IsValid || model == null || model.Id == 0) { return(Response(new { Success = false, Message = "Invalid data" })); } var teamPage = _teamPageService.Get(model.Id); //check if the page exists or not & the person editing actually owns the resource if (teamPage.CreatedBy != ApplicationContext.Current.CurrentUser.Id && !ApplicationContext.Current.CurrentUser.IsAdministrator()) { return(Response(new { Success = false, Message = "Unauthorized" })); } teamPage.Description = model.Description; teamPage.Name = model.Name; teamPage.TeamPictureId = model.TeamPictureId; //update the updation date teamPage.UpdatedOn = DateTime.UtcNow; //update now _teamPageService.Update(teamPage); return(RespondSuccess(new { TeamPage = teamPage.ToModel(_mediaService) })); }
public IHttpActionResult Put(TeamPageModel model) { if (!ModelState.IsValid || model == null || model.Id == 0) { return(Response(new { Success = false, Message = "Invalid data" })); } var teamPage = _teamPageService.GetById(model.Id); //check if the page exists or not & the person editing actually owns the resource if (teamPage.CreatedBy != _workContext.CurrentCustomer.Id && !_workContext.CurrentCustomer.IsAdmin()) { return(Response(new { Success = false, Message = "Unauthorized" })); } Mapper.Map(model, teamPage); //update the updation date teamPage.UpdatedOn = DateTime.UtcNow; //update now _teamPageService.Update(teamPage); return(Response(new { Success = true })); }
public IHttpActionResult Get(int id) { var teamPage = _teamPageService.GetById(id); if (teamPage == null) { return(NotFound()); } var model = new TeamPageModel() { CreatedBy = teamPage.CreatedBy, CreatedOn = teamPage.CreatedOn, Description = teamPage.Description, Id = teamPage.Id, Name = teamPage.Name, TeamPictureId = teamPage.TeamPictureId, UpdatedBy = teamPage.UpdatedBy, UpdatedOn = teamPage.UpdatedOn }; model.Groups = GetTeamPageGroupPublicModels(id); //is the page editable model.IsEditable = _workContext.CurrentCustomer.IsAdmin() || _workContext.CurrentCustomer.Id == teamPage.CreatedBy; model.TeamPictureUrl = _pictureService.GetPictureUrl(model.TeamPictureId, 0, false); return(Response(new { Success = true, TeamPage = model })); }
public ActionResult Index(int teamId) { var model = new TeamPageModel() { Id = teamId }; return(View("mobSocial/TeamPage/Index", model)); }
// todo add security to pertinent actions public ActionResult Team(int teamId) { var team = _socialNetworkService.GetTeam(teamId); if (teamId == 1 && team == null) { CreateSampleData(); team = _socialNetworkService.GetTeam(teamId); } var model = new TeamPageModel() { TeamName = team.Name, TeamDescription = team.Description, TeamPictureUrl = team.TeamPictureUrl }; var groupPages = team.GroupPages.OrderBy(x => x.DisplayOrder); // team groups foreach (var group in groupPages) { var groupModel = new TeamPageGroupModel() { Name = group.Name, Description = group.Description, }; var groupMembers = group.Members.OrderBy(x => x.DisplayOrder); // team group members foreach (var member in groupMembers) { var memberCustomer = _customerService.GetCustomerById(member.CustomerId); var memberThumbnailUrl = _pictureService.GetPictureUrl( memberCustomer.GetAttribute <int>(SystemCustomerAttributeNames.AvatarPictureId), 150, true); groupModel.Members.Add(new TeamPageGroupMemberModel() { DisplayName = memberCustomer.GetFullName(), ProfileUrl = Url.RouteUrl("CustomerProfileUrl", new { SeName = SeoExtensions.GetSeName(memberCustomer, 0) }), ThumbnailUrl = memberThumbnailUrl }); } model.Groups.Add(groupModel); } return(View(MobSocialConstant.ViewsPath + "/mobSocial/TeamPage.cshtml", model)); }
public void OnGet_RequestPage() { // Arrange TeamPageModel pageModel = new TeamPageModel(); // Act var result = pageModel.Page(); // Assert Assert.IsType <PageResult>(result); }
public static TeamPageModel ToEntityModel(this TeamPage teamPage, IMediaService mediaService) { var model = new TeamPageModel() { Id = teamPage.Id, TeamPictureUrl = mediaService.GetPictureUrl(teamPage.TeamPictureId), Name = teamPage.Name, Description = teamPage.Description, CreatedBy = teamPage.CreatedBy, CreatedOn = teamPage.CreatedOn, UpdatedBy = teamPage.UpdatedBy, UpdatedOn = teamPage.UpdatedOn }; return(model); }
public IHttpActionResult Post(TeamPageModel model) { if (!ModelState.IsValid || model == null) { return(Response(new { Success = false, Message = "Invalid data" })); } var teamPage = Mapper.Map <TeamPage>(model); teamPage.CreatedBy = _workContext.CurrentCustomer.Id; teamPage.CreatedOn = DateTime.UtcNow; teamPage.UpdatedOn = DateTime.UtcNow; //save to db now _teamPageService.Insert(teamPage); return(Response(new { Success = true, Url = Url.RouteUrl("TeamPage", new RouteValueDictionary() { { "TeamId", teamPage.Id } }) })); }