protected void LnkSubscribeUser_Click(object sender, EventArgs e) { lblError.Visible = false; lblSubscribed.Visible = false; LinkButton btn = sender as LinkButton; GridViewRow row = btn.NamingContainer as GridViewRow; long groupId = Convert.ToInt64(gvAllGroups.DataKeys[row.RowIndex].Value.ToString()); HttpCookie cookie = Request.Cookies["loginName"]; IIoCManager ioCManager = (IIoCManager)HttpContext.Current.Application["managerIoC"]; IRecommendationGroupService recommendationGroupService = ioCManager.Resolve <IRecommendationGroupService>(); try { recommendationGroupService.AddUserToGroup(cookie.Value, groupId); var lnk = (LinkButton)row.FindControl("lnkSubscribeUser"); if (lnk != null) { lnk.Visible = false; } var lbl = (Label)row.FindControl("lblSubscribed"); if (lbl != null) { lbl.Visible = true; } this.lblSubscribed.Visible = true; } catch (Exception) { lblError.Text = "Something go wrong"; lblError.Visible = true; } }
protected void Page_Load(object sender, EventArgs e) { //if (!Page.IsPostBack) //{ IIoCManager ioCManager = (IIoCManager)HttpContext.Current.Application["managerIoC"]; IRecommendationGroupService recommendationGroupService = ioCManager.Resolve <IRecommendationGroupService>(); List <DTOGroups> groups = recommendationGroupService.ShowAllGroups(); if (groups.Count == 0) { this.lblNoGroups.Visible = true; return; } else { this.lblGroups.Visible = true; } #region //Forma opcional : Utilizando paquete Nuget: FastMember DataTable table = new DataTable(); using (var reader = ObjectReader.Create(groups, "group_usersId", "gr_name", "gr_description", "gr_amount_users", "gr_amount_recommendation")) { table.Load(reader); } #endregion //Forma opcional : Utilizando paquete Nuget: FastMember this.gvAllGroups.DataSource = table; this.DataBind(); this.gvAllGroups.Columns[0].Visible = false; }
protected void Page_Load(object sender, EventArgs e) { IIoCManager ioCManager = (IIoCManager)HttpContext.Current.Application["managerIoC"]; IRecommendationGroupService recommendationGroupService = ioCManager.Resolve <IRecommendationGroupService>(); HttpCookie cookie = Request.Cookies["loginName"]; DataTable dataTable = new DataTable(); HashSet <DTORecommendation> recommendations = recommendationGroupService.ShowUserRecommendations(cookie.Value); if (recommendations.Count == 0) { this.lblNorecommendations.Visible = true; this.lblRecommendations.Visible = false; return; } using (var reader = ObjectReader.Create(recommendations, "recommendationId", "eventId", "login_user", "eventName", "recommendation_text")) { dataTable.Load(reader); } this.gvRecommendations.DataSource = dataTable; this.DataBind(); gvRecommendations.Columns[0].Visible = false; gvRecommendations.Columns[1].Visible = false; }
/// <summary>Handles the RowDeleting event of the gvGroups control.</summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="GridViewDeleteEventArgs" /> instance containing the event data.</param> protected void GvGroups_RowDeleting(object sender, GridViewDeleteEventArgs e) { lblErrorOwner.Visible = false; lblSuccess.Visible = false; //TableCell cell = gvGroups.Rows[e.RowIndex].Cells[2]; long groupId = Convert.ToInt64(gvGroups.DataKeys[e.RowIndex].Value.ToString()); IIoCManager ioCManager = (IIoCManager)HttpContext.Current.Application["managerIoC"]; IRecommendationGroupService recommendationGroupService = ioCManager.Resolve <IRecommendationGroupService>(); HttpCookie cookie = Request.Cookies["loginName"]; try { recommendationGroupService.AbandonGroup(cookie.Value, groupId); DataTable dt = (DataTable)ViewState["groups"]; dt.Rows[e.RowIndex].Delete(); dt.AcceptChanges(); ViewState["groups"] = dt; lblSuccess.Visible = true; gvGroups.DataSource = dt; gvGroups.DataBind(); } catch (OwnerGroupAbandonException) { lblErrorOwner.Visible = true; e.Cancel = true; return; } }
/// <summary>Creates the group click.</summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void CreateGroupClick(object sender, EventArgs e) { if (Page.IsValid) { try { string groupName = this.txtNameGroup.Text; string groupDescription = txtDescriptionGroup.Value; IIoCManager ioCManager = (IIoCManager)Application["managerIoC"]; IRecommendationGroupService recommendationGroupService = ioCManager.Resolve <IRecommendationGroupService>(); HttpCookie cookie = Request.Cookies["loginName"]; try { recommendationGroupService.CreateGroup(groupName, groupDescription, cookie.Value); //Response.Redirect(Response.ApplyAppPathModifier("~/Pages/MainPage.aspx")); this.lblGroupCreated.Visible = true; this.btnCreateGroup.Visible = false; } catch (GroupAlreadyExistsException) { this.lblGroupError.Visible = true; } } catch (DuplicateInstanceException) { this.lblGroupError.Visible = true; } } }
/// <summary>Handles the RowDataBound event of the gvAllGroups control.</summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="GridViewRowEventArgs" /> instance containing the event data.</param> protected void GvAllGroups_RowDataBound(object sender, GridViewRowEventArgs e) { if (SessionManager.IsUserAuthenticated(Context) && e.Row.RowType == DataControlRowType.DataRow) { HttpCookie cookie = Request.Cookies["loginName"]; IIoCManager ioCManager = (IIoCManager)HttpContext.Current.Application["managerIoC"]; IRecommendationGroupService recommendationGroupService = ioCManager.Resolve <IRecommendationGroupService>(); //Quiza despues en vez de DTOs, añado al viewState todos los ids. List <DTOGroupsUser> groupsFromUser = recommendationGroupService.ShowUserGroups(cookie.Value); long idRow = Convert.ToInt64(gvAllGroups.DataKeys[e.Row.RowIndex].Values[0].ToString()); bool coincidence = false; //this.lblError.Text += "RowDataBound id= " + idRow; //this.lblError.Visible = true; foreach (DTOGroupsUser group in groupsFromUser) { if (idRow == group.group_usersId) { coincidence = true; break; } } if (coincidence) { var lbl = (Label)e.Row.FindControl("lblSubscribed"); var lnk = (HyperLink)e.Row.FindControl("lnkSubscribeAuth"); if (lbl != null) { //lbl.Text = "Already subscribed"; lbl.Visible = true; } if (lnk != null) { lnk.Visible = false; } } else { var lnk = (HyperLink)e.Row.FindControl("lnkSubscribeAuth"); if (lnk != null) { lnk.Visible = false; } var lnkAuthUser = (LinkButton)e.Row.FindControl("lnkSubscribeUser"); if (lnkAuthUser != null) { lnkAuthUser.Visible = true; } } } }
public static void MyClassInitialize(TestContext testContext) { kernel = TestManager.ConfigureNInjectKernel(); recommendationGroupService = kernel.Get <IRecommendationGroupService>(); userService = kernel.Get <IUserService>(); userProfileDao = kernel.Get <IUserProfileDao>(); sportEventDao = kernel.Get <ISportEventDao>(); recommendationDao = kernel.Get <IRecommendationDao>(); groupUsersDao = kernel.Get <IGroupUsersDao>(); sportEventService = kernel.Get <ISportEventService>(); categoryDao = kernel.Get <ICategoryDao>(); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { long eventId; try { eventId = Convert.ToInt64(Request.Params.Get("eventId")); } catch (ArgumentNullException) { //Hacer un redirect a los grupos eventId = 0; } if (eventId != 0) { ViewState["eventId"] = eventId; IIoCManager ioCManager = (IIoCManager)HttpContext.Current.Application["managerIoC"]; IRecommendationGroupService recommendationGroupService = ioCManager.Resolve <IRecommendationGroupService>(); HttpCookie cookie = Request.Cookies["loginName"]; List <DTOGroupsUser> groupsUsers = recommendationGroupService.ShowUserGroups(cookie.Value); if (groupsUsers.Count == 0) { this.lblEvents.Visible = false; lclRecommendation.Visible = false; txtRecommend.Visible = false; lblNoGroupsToRecommend.Visible = true; lblSelectCheckBox.Visible = false; this.btnCreateRecommendation.Visible = false; return; } DataTable table = new DataTable(); using (var reader = ObjectReader.Create(groupsUsers, "group_usersId", "gr_name")) { table.Load(reader); } ViewState["groupsRecommend"] = table; this.gvGroups.DataSource = (DataTable)ViewState["groupsRecommend"]; this.DataBind(); this.gvGroups.Columns[0].Visible = false; } else { lblNoeventId.Visible = true; txtRecommend.Visible = false; btnCreateRecommendation.Visible = false; } } }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { IIoCManager ioCManager = (IIoCManager)HttpContext.Current.Application["managerIoC"]; IRecommendationGroupService recommendationGroupService = ioCManager.Resolve <IRecommendationGroupService>(); HttpCookie cookie = Request.Cookies["loginName"]; List <DTOGroupsUser> groupsUsers = recommendationGroupService.ShowUserGroups(cookie.Value); if (groupsUsers.Count == 0) { lblNoGroups.Visible = true; lblGroups.Visible = false; return; } lblGroups.Visible = false; #region //Forma normal //this.gvGroups.DataSource = groupsUsers; //this.DataBind(); #endregion //Forma normal #region //Forma opcional : Utilizando paquete Nuget: FastMember DataTable table = new DataTable(); using (var reader = ObjectReader.Create(groupsUsers, "group_usersId", "gr_name")) { table.Load(reader); } ViewState["groups"] = table; this.gvGroups.DataSource = (DataTable)ViewState["groups"];; this.DataBind(); this.gvGroups.Columns[0].Visible = false; #endregion //Forma opcional : Utilizando paquete Nuget: FastMember } }
protected void BtnCreateRecommendation_Click(object sender, EventArgs e) { this.lblError.Visible = false; this.lblSuccess.Visible = false; this.lblNoGroupsSelected.Visible = false; IIoCManager ioCManager = (IIoCManager)HttpContext.Current.Application["managerIoC"]; IRecommendationGroupService recommendationGroupService = ioCManager.Resolve <IRecommendationGroupService>(); List <long> groupsChecked = new List <long>(); foreach (GridViewRow row in gvGroups.Rows) { long groupId = Convert.ToInt64(gvGroups.DataKeys[row.RowIndex].Value.ToString()); var chk = row.FindControl("chkGroup") as CheckBox; if (chk != null && chk.Checked) { groupsChecked.Add(groupId); } } if (groupsChecked.Count != 0) { try { long eventId = (long)ViewState["eventId"]; HttpCookie cookie = Request.Cookies["loginName"]; recommendationGroupService.AddRecommendation(cookie.Value, eventId, groupsChecked, this.txtRecommend.Value); } catch (Exception) { lblError.Visible = true; } this.lblSuccess.Visible = true; } else { this.lblNoGroupsSelected.Visible = true; } }