Ejemplo n.º 1
0
        protected void BtnCreateComission_Click(object sender, EventArgs e)
        {
            int Ano;

            int.TryParse(TbAno.Text, out Ano);


            if (!Page.IsValid)
            {
                return;
            }
            ApplicationDbContext context = new ApplicationDbContext();
            var    UserManager           = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context));
            string user = User.Identity.GetUserId();

            BtnCreateComission.Enabled = false; //Prevenir Flood
            Random rnd = new Random();

            if (LbOficinas.GetSelectedIndices().Count() > 1)
            {
                int var, groupno;

                do
                {
                    groupno = rnd.Next(1, 10000);
                    var     = Commissions.CheckIfGroupExists(groupno);
                    if (var == -1)
                    {
                        Response.Redirect("~/Error.aspx");
                    }
                } while (var != 0);

                foreach (int i in LbOficinas.GetSelectedIndices())
                {
                    if (Commissions.CreateComissionGroup(TbModelo.Text, DdlTipo.SelectedValue, LbOficinas.Items[i].Value, Ano, TbDetails.Text, user, groupno) == false)
                    {
                        Response.Redirect("~/Error.aspx");
                    }
                }
            }
            else
            {
                foreach (int i in LbOficinas.GetSelectedIndices())
                {
                    if (Commissions.CreateComission(TbModelo.Text, DdlTipo.SelectedValue, LbOficinas.Items[i].Value, Ano, TbDetails.Text, user) == false)
                    {
                        Response.Redirect("~/Error.aspx");
                    }
                }
            }

            Response.Redirect("ComissionCreated.aspx");
        }