Ejemplo n.º 1
0
        public void DoDelRace()
        {
            bool sigue = true;
            string messageError = "";

            //Verify race exists
            if (txbxUserName.Text == "")
            {
                sigue = false;
                messageError = "No hay competiciones que quitar.";
            }

            if (sigue)
            {
                if (actualRaceId == 0)
                {
                    messageError = "Seleccione una competición para quitar de la tabla.";
                    sigue = false;
                }
            }

            if (sigue)
            {
                //Load data for username
                using (var db = new ClubSiteContext())
                {
                    Member aMember = new Member();
                    Race aRace = new Race();
                    aMember = (from m in db.Members where m.UserName == memberUsed.UserName select m).FirstOrDefault();
                    aRace = (from r in db.Races where r.Id == actualRaceId select r).FirstOrDefault();
                    try
                    {
                        aRace.Members.Remove(aMember);
                        db.SaveChanges();
                        LoadDataInGridForRacesForClubber();
                        X.Msg.Alert("Atención", memberUsed.UserName + " quitad@ de la competición.").Show();
                    }
                    catch (Exception)
                    {
                        X.Msg.Alert("Atención", "Hubo un problema al quitar a " + memberUsed.UserName + " de la competición seleccionada.").Show();
                    }

                }
            }

            if (!sigue)
            {
                X.Msg.Alert("Atención", messageError).Show();
            }
        }
Ejemplo n.º 2
0
        public void DoSave()
        {
            bool sigue = true;
            bool nuevo = false;
            string messageError = null;

            //Save if conditions are ok.
            if (sigue)
            {
                //Update actual member
                actualUserName = txbxUserName.Text;
                using (var db = new ClubSiteContext())
                {
                    Member aMember = (from members in db.Members
                                      where members.UserName == actualUserName
                                      select members).FirstOrDefault();
                    if (aMember == null)
                    { //New User
                        aMember = new Member();
                        aMember.UserName = actualUserName;
                        nuevo = true;
                    }
                    try
                    {
                        aMember.FirstName = txbxFirstName.Text;
                        aMember.SecondName = txbxSecondName.Text;
                        aMember.BlogURL = txbxBlogURL.Text;
                        aMember.Memo = txbxMemo.Text;
                        aMember.DNI = txbxDNI.Text;
                        if (txbxBdate.Value.ToString() == "01/01/0001 0:00:00")
                        {
                            aMember.BirthDate = null;
                        }
                        else
                        {
                            try
                            {
                                aMember.BirthDate = Convert.ToDateTime(txbxBdate.Text);
                            }
                            catch
                            {
                                aMember.BirthDate = null;
                            }
                        }
                        aMember.Federated = chbxFederated.Checked;
                        aMember.State = chBxActiveUser.Checked;
                        aMember.Visible = chbxVisible.Checked;
                        if (FileUploadNumber.HasFile)
                        {
                            aMember.NImageURL = "../Images/Clubbers/" + FileUploadNumber.FileName; //imgNImage.ImageUrl;
                        }
                        else
                        {
                            aMember.NImageURL = memberUsed.NImageURL;
                        }
                        if (FileUploadImage.HasFile)
                        {
                            aMember.ImageURL = "../Images/Clubbers/" + FileUploadImage.FileName; //imgImage.ImageUrl;
                        }
                        else
                        {
                            aMember.ImageURL = memberUsed.ImageURL;
                        }
                        aMember.Tlf = txbxTlf.Text;
                        aMember.Mobile = txbxMobile.Text;
                        aMember.EMail = txbxEMail.Text;
                        if (nuevo)
                        {
                            aMember.Address = new Address();
                        }
                        aMember.Address.Street = txbxStreet.Text;
                        aMember.Address.Number = txbxNumber.Text;
                        aMember.Address.City = txbxCity.Text;
                        aMember.Address.Country = txbxCountry.Text;
                        aMember.Address.PostalCode = txbxPostalCode.Text;
                        aMember.Number = txbxClubberNumber.Text;
                        if (nuevo)
                        {
                            db.Members.Add(aMember);
                        }
                        db.SaveChanges();
                        memberUsed.CopyMember(aMember);
                        oldMemberUsed.CopyMember(aMember);
                        Notification.Show(new NotificationConfig { Title = "Aviso", Icon = Icon.Information, Html = "Datos del usuario "+ actualUserName +" grabados" });

                    }
                    catch (Exception)
                    {
                        sigue = false;
                        messageError = " No se grabaron los datos, se produjo un error al acceder a la base";
                    }
                    GPClubbers.DataBind();
                    newNumber = false;
                    newImage = false;
                }
            }
            if (!sigue)
            {
                X.Msg.Alert("Atención", messageError).Show();
            }
        }
Ejemplo n.º 3
0
        public void DoDel()
        {
            //1-Delete user in Member table in ClubSite.mdf DB
            using (var db = new ClubSiteContext())
            {
                //Delete the user
                var aClubberToDelete = (from c in db.Members
                                        where c.UserName == actualUserName
                                        select c).Single();
                db.Members.Remove(aClubberToDelete);
                db.SaveChanges();
                //Delete de Image files for the user
                if (System.IO.File.Exists(Server.MapPath(imgNImage.ImageUrl)))
                    System.IO.File.Delete(Server.MapPath(imgNImage.ImageUrl));
                if (System.IO.File.Exists(Server.MapPath(imgImage.ImageUrl)))
                    System.IO.File.Delete(Server.MapPath(imgImage.ImageUrl));
                Notification.Show(new NotificationConfig { Title = "Aviso", Icon = Icon.Information, Html = "Usuario "+ actualUserName +" borrado correctamente." });
            }

            //2-Delete user in Membership and Users tables in ClubSiteBDDefault DB
            Membership.DeleteUser(actualUserName);

            //3-Load data for the first member into the form.
            using (var db = new ClubSiteContext())
            {
                var aMember = (from members in db.Members
                               orderby members.UserName
                               select members).FirstOrDefault();

                if (aMember == null)
                {
                    actualUserName = "";
                    memberUsed = new Member();
                    LoadMemberInForm(memberUsed);
                    Notification.Show(new NotificationConfig { Title = "Aviso", Icon = Icon.Information, Html = "Ya no hay ningún usuario registrado. Para crear nuevos usuarios vaya al formulario de registro." });
                }
                else
                {
                    LoadMemberInForm(aMember);
                    memberUsed.CopyMember(aMember);
                }
                oldMemberUsed.CopyMember(memberUsed);
            }
            //4-Refresh the GridView
            GPClubbers.DataBind();
        }
Ejemplo n.º 4
0
        public void DoDelAllRaces()
        {
            //Del all races between fromDate and toDate
            DateTime fromDate = dtfFromDate.SelectedDate;
            DateTime toDate = dtfToDate.SelectedDate;
            using (var db = new ClubSiteContext())
            {
                Member aMember = (from m in db.Members
                                  where m.UserName == memberUsed.UserName
                                  select m).FirstOrDefault();
                if (aMember == null)
                {
                    // The item wasn't found
                    ModelState.AddModelError("", String.Format("Clubber : {0} no encontrada", memberUsed.UserName));
                    X.Msg.Alert("Atención", "Clubber no encontrado. Borrado de competiciones cancelado,").Show();
                    return;
                }

                var dataToRemove = from r in aMember.Races where r.RaceDate >= fromDate && r.RaceDate <= toDate select r;
                foreach (Race aRaceToRemove in dataToRemove.ToList())
                {
                    aMember.Races.Remove(aRaceToRemove);
                }
                db.SaveChanges();
                LoadDataInGridForRacesForClubber();
                X.Msg.Alert("Atención", "Todas las competiciones del clubber entre el " + fromDate.ToShortDateString() +
                                        " y el " + toDate.ToShortDateString() + "han sido borradas.").Show();
            }
        }
Ejemplo n.º 5
0
        public void DoSave()
        {
            bool sigue = true;
            string messageError = null;

            //Save if conditions are ok.
            if (sigue)
            {
                using (var db = new ClubSiteContext())
                {
                    Race aRace;
                    if (rUsed.Id == 0)
                    { //New Race
                        aRace = new Race();
                        aRace.Name = txbxName.Text;
                        aRace.Name = txbxName.Text;
                        aRace.RaceDate = Convert.ToDateTime(txbxDate.Text);
                        aRace.ImageURL = rUsed.ImageURL;
                        aRace.RaceTypeID = aRaceIdSelectedInCombo;
                        try
                        {
                            aRace.PartFem = Convert.ToInt16(txbxPartGenFem.Text);
                        }
                        catch (Exception)
                        {
                            aRace.PartFem = 0;
                        }
                        try
                        {
                            aRace.PartMasc = Convert.ToInt16(txbxPartGenMasc.Text);
                        }
                        catch (Exception)
                        {
                            aRace.PartMasc = 0;
                        }
                        Address anAddres = new Address(txbxStreet.Text, txbxNumber.Text, txbxCity.Text, txbxCountry.Text, txbxPostalCode.Text);
                        aRace.Address = anAddres;
                        aRace.Memo = txbxMemo.Text;
                        string aux = ReformatNumber(txbxLatitud.Text);
                        if (aux == null)
                            aRace.Latitud = 0;
                        else
                        {
                            aRace.Latitud = Convert.ToDouble(aux);
                        }

                        aux = ReformatNumber(txbxLongitud.Text);
                        if (aux == null)
                            aRace.Longitud = 0;
                        else
                        {
                            aRace.Longitud = Convert.ToDouble(aux);
                        }

                        db.Races.Add(aRace);
                        messageError = "Nueva competición grabada";
                    }
                    else
                    { //Update actual Race
                        aRace = (from races in db.Races
                                 where races.Id == rUsed.Id
                                 select races).FirstOrDefault();
                        if (aRace == null)
                        {
                            // The item wasn't found
                            ModelState.AddModelError("", String.Format("Competición con Id : {0} no encontrada", rUsed.Id));
                            X.Msg.Alert("Atención", "Competición no encontrada. Grabación de datos cancelada.").Show();
                            return;
                        }
                        aRace.Name = txbxName.Text;
                        aRace.RaceDate = Convert.ToDateTime(txbxDate.Text);
                        aRace.ImageURL = rUsed.ImageURL;
                        aRace.RaceTypeID = aRaceIdSelectedInCombo;
                        Address anAddres = new Address(txbxStreet.Text, txbxNumber.Text, txbxCity.Text, txbxCountry.Text, txbxPostalCode.Text);
                        aRace.Address = anAddres;
                        aRace.Memo = txbxMemo.Text;
                        string aux = ReformatNumber(txbxLatitud.Text);
                        if (aux == null)
                            aRace.Latitud = 0;
                        else
                        {
                            aRace.Latitud = Convert.ToDouble(aux);
                        }

                        aux = ReformatNumber(txbxLongitud.Text);
                        if (aux == null)
                            aRace.Longitud = 0;
                        else
                        {
                            aRace.Longitud = Convert.ToDouble(aux);
                        }
                        messageError = "Datos de competición actualizados";
                    }
                    db.SaveChanges();
                    LoadRaceInForm(aRace);  //To update the ID (identity file)
                    rUsed.CopyRace(aRace);
                    oldRUsed.CopyRace(rUsed);
                    StoreGPRaces.DataBind();
                    X.Msg.Alert("Atención", messageError).Show();
                }
                btnBorrar.Enabled = true;
            }
            else
            {
                X.Msg.Alert("Atención", messageError).Show();
            }
        }
Ejemplo n.º 6
0
        public void DoAddRace()
        {
            bool sigue = true;
            string messageError = "";

            //Load data for Race/Clubber
            using (var db = new ClubSiteContext())
            {
                Member aMember = new Member();
                Race aRace = new Race();
                aMember = (from m in db.Members where m.UserName == memberUsed.UserName select m).FirstOrDefault();
                aRace = (from r in db.Races where r.Id == actualRaceId select r).FirstOrDefault();

                //verify if member is in members list for race
                if (aRace.Members.Contains(aMember) == true)
                {
                    messageError = memberUsed.UserName + " ya esta inscrit@ en esa competición.";
                    sigue = false;
                }
                else
                {
                    try
                    {
                        aRace.Members.Add(aMember);
                        db.SaveChanges();
                        LoadDataInGridForRacesForClubber();
                        X.Msg.Alert("Atención", "Se ha inscrito a " + memberUsed.UserName + " en la competición.").Show();
                    }
                    catch (Exception)
                    {
                        X.Msg.Alert("Atención", "Hubo un problema al añadir a " + memberUsed.UserName + "a la lista de participantes en la competición.").Show();
                    }
                }
            }

            if (!sigue)
            {
                X.Msg.Alert("Atención", messageError).Show();
            }
        }
Ejemplo n.º 7
0
        public void DoDelAllAG()
        {
            bool sigue = true;
            string grupo = "";

            if (sigue)
            {
                //Load data for age group
                using (var db = new ClubSiteContext())
                {
                    var aListOfAG = from ag in db.RaceAgeGroups where ag.RaceID == rUsed.Id select ag;
                    if (aListOfAG != null)
                    {
                        try
                        {
                            foreach (RaceAgeGroup ag in aListOfAG.ToList())
                            {
                                db.RaceAgeGroups.Remove(ag);
                            }
                            db.SaveChanges();
                            LoadDataInGridForAgeGroups();
                            X.Msg.Alert("Atención","Todos los grupos de edad han sido quitados de la competición.").Show();
                        }
                        catch (Exception)
                        {
                            X.Msg.Alert("Atención", "Hubo un problema al quitar el grupo de edad " + grupo + " de la competición.").Show();
                        }
                    }

                }
            }
        }
Ejemplo n.º 8
0
        public void DoDel()
        {
            Notification.Show(new NotificationConfig { Title = "Aviso", Icon = Icon.Information, Html = "Borrando el deporte en pantalla edición" });
            if (sportUsed.SportID == 0)
            { //No sport selected
                X.Msg.Alert("Atención", "No hay nada que borrar ya que no hay deportes registrados en la base de datos.").Show();
            }
            else
            {
                using (var db = new ClubSiteContext())
                {
                    Sport item = (from sports in db.Sports
                                  where sports.SportID == sportUsed.SportID
                                  select sports).FirstOrDefault();
                    if (item == null)
                    {
                        // The item wasn't found
                        ModelState.AddModelError("", String.Format("Deporte con id : {0} no encontrado", sportUsed.SportID));
                        X.Msg.Alert("Atención", "Deporte no encontrado. Borrado cancelado,").Show();
                        return;
                    }
                    db.Sports.Remove(item);
                    db.SaveChanges();
                    this.Store1.DataBind();
                    X.Msg.Alert("Atención", "Tipo de carrera borrada.").Show();

                    //Load data for first race type
                    sportUsed = (from sports in db.Sports
                                 orderby sports.Name
                                 select sports).FirstOrDefault();
                    if (sportUsed == null)
                    {
                        //Last item was erased. No items in BD.
                        sportUsed = new Sport();
                        X.Msg.Alert("Atención", "No queda ningún deporte registrado en la Base de datos.").Show();
                    }
                    oldSportUsed.CopySport(sportUsed);
                    //Loads model object data into form
                    LoadSportInForm(sportUsed);
                }
            }
        }
Ejemplo n.º 9
0
        public void DoDel()
        {
            Notification.Show(new NotificationConfig { Title = "Aviso", Icon = Icon.Information, Html = "Borrando la competición en pantalla." });
            if (rUsed.Id == 0)
            { //No Race selected
                X.Msg.Alert("Atención", "No hay nada que borrar ya que no hay competiciones registradas.").Show();
            }
            else
            {
                //Del race
                using (var db = new ClubSiteContext())
                {
                    Race item = (from races in db.Races
                                 where races.Id == rUsed.Id
                                 select races).FirstOrDefault();
                    if (item == null)
                    {
                        // The item wasn't found
                        ModelState.AddModelError("", String.Format("Competición con id : {0} no encontrada", rUsed.Id));
                        X.Msg.Alert("Atención", "Competición no encontrada. Borrado cancelado,").Show();
                        return;
                    }
                    db.Races.Remove(item);
                    db.SaveChanges();
                    this.StoreGPRaces.DataBind();
                    X.Msg.Alert("Atención", "Competición borrada.").Show();

                    //Load data for first race type
                    rUsed = (from races in db.Races
                             orderby races.RaceDate descending, races.Name
                             select races).FirstOrDefault();
                    if (rUsed == null)
                    {
                        //Last item was erased. No items in BD.
                        rUsed = new Race();
                        X.Msg.Alert("Atención", "No queda ninguna competición registrada en la Base de datos.").Show();
                    }
                    oldRUsed.CopyRace(rUsed);
                    //Loads model object data into form
                    LoadRaceInForm(rUsed);
                }
            }
        }
Ejemplo n.º 10
0
        public void DoDelAG()
        {
            bool sigue= true;
            string grupo="";

            //Take age group rname from GridView
            CellSelectionModel sm = this.GPAgeGroupsEnComp.GetSelectionModel() as CellSelectionModel;
            Int32 aGAId = Convert.ToInt32(sm.SelectedCell.RecordID);

            using (var db = new ClubSiteContext())
            {
                RaceAgeGroup aAG = (from ag in db.RaceAgeGroups where ag.Id == aGAId select ag).FirstOrDefault();
                if (aAG == null)
                {
                    sigue = false;
                    X.Msg.Alert("Atención", "No se encontró el grupo de edad " + grupo + " de la competición.").Show();
                }
                else
                {
                    grupo = aAG.Name;
                }
            }

            if (sigue)
            {
                //Load data for age group
                using (var db = new ClubSiteContext())
                {
                    RaceAgeGroup aAG = new RaceAgeGroup();
                    aAG = (from ag in db.RaceAgeGroups where ag.Id == aGAId select ag).FirstOrDefault();
                    if (aAG != null)
                    {
                        try
                        {
                            db.RaceAgeGroups.Remove(aAG);
                            db.SaveChanges();
                            LoadDataInGridForAgeGroups();
                            X.Msg.Alert("El grupo de edad", grupo + " ha sido quitado de la competición.").Show();
                        }
                        catch (Exception)
                        {
                            X.Msg.Alert("Atención", "Hubo un problema al quitar el grupo de edad " + grupo + " de la competición.").Show();
                        }
                    }

                }
            }
        }
Ejemplo n.º 11
0
 public void DoAddAG()
 {
     //Load data for username
     using (var db = new ClubSiteContext())
     {
         try
         {
             RaceAgeGroup aRaceAgeGroup = new RaceAgeGroup();
             aRaceAgeGroup.Name = txbxGEName.Text;
             aRaceAgeGroup.Part = Convert.ToInt16(txbxGEPart.Text);
             aRaceAgeGroup.RaceID = rUsed.Id;
             db.RaceAgeGroups.Add(aRaceAgeGroup);
             db.SaveChanges();
             LoadDataInGridForAgeGroups();
             X.Msg.Alert("Atención", "Se ha añadido el grupo de edad " + txbxGEName.Text + " en la competición.").Show();
         }
         catch (Exception)
         {
             X.Msg.Alert("Atención", "Hubo un problema al añadir el grupo de edad " + txbxGEName.Text + "a la competición.").Show();
         }
     }
 }
Ejemplo n.º 12
0
        protected void RegisterUser_CreatedUser(object sender, EventArgs e)
        {
            //save aditional DataBind of user
            using (var bd = new ClubSiteContext())
            {
                try
                {
                    string aUserName = ((TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("UserName")).Text;
                    string aFirstName = ((TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("txbxName")).Text;
                    string aSecondName = ((TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("txbxSecondName")).Text;
                    string aBlogURL = ((TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("txbxBlog")).Text;
                    string aMemo = ((TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("txbxMemo")).Text;
                    string aDNI = ((TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("txbxDNI")).Text;
                    DateTime? aBirthDate = null;
                    try
                    {
                        aBirthDate = Convert.ToDateTime(((TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("txbxBdate")).Text);
                    }
                    catch
                    {
                        aBirthDate = null;
                    }
                    DateTime aRegDate = DateTime.Now;
                    bool aState = false;
                    bool visible = false;
                    bool federated = ((CheckBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("chbxFederated")).Checked;
                    string aNImageURL = ((Image)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("imgNImageURL")).ImageUrl;
                    string anImageURL = ((Image)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("imgImageURL")).ImageUrl;
                    string aTlf = ((TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("txbxTlf")).Text;
                    string aMobile = ((TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("txbxMobile")).Text;
                    string anEMail = ((TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("Email")).Text;
                    string aClubNumber = ((TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("txbxClubNumber")).Text;
                    string aStreet = ((TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("txbxStreet")).Text;
                    string aNumber = ((TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("txbxNumber")).Text;
                    string aCity = ((TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("txbxCity")).Text;
                    string aCountry = ((TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("txbxCountry")).Text;
                    string aPostalCode = ((TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("txbxPostalCode")).Text;
                    Address anAddress = new Address(aStreet, aNumber, aCity, aCountry, aPostalCode);
                    Member aMember = new Member(aUserName, aClubNumber, aFirstName, aSecondName, aDNI, anAddress, aTlf, aMobile, anEMail,
                        aState, federated, visible, aBirthDate, aMemo, anImageURL, aNImageURL, aBlogURL);
                    bd.Members.Add(aMember);
                    bd.SaveChanges();
                }
                catch (Exception)
                {
                    throw;
                }
            }

            FormsAuthentication.SetAuthCookie(RegisterUser.UserName, createPersistentCookie: false);

            string continueUrl = RegisterUser.ContinueDestinationPageUrl;
            if (!OpenAuth.IsLocalUrl(continueUrl))
            {
                continueUrl = "~/";
            }
            Response.Redirect(continueUrl);
        }
Ejemplo n.º 13
0
 public void DoSave()
 {
     //Verify conditions
     if (txfName.Text == "")
     {
         X.Msg.Alert("Atención", "Falta el nombre del deporte.").Show();
     }
     else
     {
         // Load the item here, e.g. item = MyDataLayer.Find(id);
         using (var db = new ClubSiteContext())
         {
             Sport aSport;
             if (sportUsed.SportID == 0)
             { //New Sport
                 aSport = new Sport();
                 aSport.Name = txfName.Text;
                 aSport.Memo = txfMemo.Text;
                 db.Sports.Add(aSport);
             }
             else
             { //Update actual Sport
                 aSport = (from sports in db.Sports
                           where sports.SportID == sportUsed.SportID
                           select sports).FirstOrDefault();
                 if (aSport == null)
                 {
                     // The item wasn't found
                     ModelState.AddModelError("", String.Format("Deporte con Id : {0} no encontrado", sportUsed.SportID));
                     X.Msg.Alert("Atención", "Deporte no encontrado. Grabado cancelado.").Show();
                     return;
                 }
                 aSport.SportID = Convert.ToInt32(txfId.Text);
                 aSport.Name = txfName.Text;
                 aSport.Memo = txfMemo.Text;
             }
             db.SaveChanges();
             LoadSportInForm(aSport);  //To update the ID (identity file)
             sportUsed = aSport;
             oldSportUsed.CopySport(sportUsed);
             GridPanel1.DataBind();
             X.Msg.Alert("Atención", "Datos de deporte grabados.").Show();
         }
         btnBorrar.Enabled = true;
     }
 }
Ejemplo n.º 14
0
        public void DoDel()
        {
            if (sponsorUsed.SponsorId == 0)
            { //No Race Type selected
                X.Msg.Alert("Atención", "No hay nada que borrar ya que no hay sponsors registrados.").Show();
            }
            else
            {
                using (var db = new ClubSiteContext())
                {
                    Sponsor item = (from sponsors in db.Sponsors
                                    where sponsors.SponsorId == sponsorUsed.SponsorId
                                    select sponsors).FirstOrDefault();
                    if (item == null)
                    {
                        // The item wasn't found
                        ModelState.AddModelError("", String.Format("Sponsor con id : {0} no encontrado", sponsorUsed.SponsorId));
                        X.Msg.Alert("Atención", "Sponsor no encontrado").Show();
                        return;
                    }
                    db.Sponsors.Remove(item);
                    db.SaveChanges();
                    this.StoreGPSponsors.DataBind();
                    X.Msg.Alert("Atención", "Sponsor borrado.").Show();

                    //Load data for first race type
                    sponsorUsed = (from sponsors in db.Sponsors
                                   orderby sponsors.Nombre
                                   select sponsors).FirstOrDefault();

                    if (sponsorUsed == null)
                    {
                        //Last item was erased. No items in BD.
                        sponsorUsed = new Sponsor();
                        X.Msg.Alert("Atención", "No queda ningún sponsor registrado en la Base de datos.").Show();
                    }

                    oldSponsorUsed.CopySponsor(sponsorUsed);
                    //Loads model object data into form
                    LoadSponsorInForm(sponsorUsed);
                }
            }
        }
Ejemplo n.º 15
0
 public void DoDelAllClubbers()
 {
     //Del all races
     using (var db = new ClubSiteContext())
     {
         Race aRace = (from races in db.Races
                       where races.Id == rUsed.Id
                       select races).FirstOrDefault();
         if (aRace == null)
         {
             // The item wasn't found
             ModelState.AddModelError("", String.Format("Competición con id : {0} no encontrada", rUsed.Id));
             X.Msg.Alert("Atención", "Competición no encontrada. Borrado cancelado,").Show();
             return;
         }
         aRace.Members.Clear();
         db.SaveChanges();
         LoadDataInGridForMembersInRace();
         X.Msg.Alert("Atención", "Clubbers inscritos en la carrera borrados.").Show();
     }
 }
Ejemplo n.º 16
0
        public void DoSave()
        {
            bool sigue = true;
            string messageError = null;

            //Save if conditions are ok.
            if (sigue)
            {
                // Load the item here, e.g. item = MyDataLayer.Find(id);
                using (var db = new ClubSiteContext())
                {
                    Sponsor aSponsor;
                    if (sponsorUsed.SponsorId == 0)
                    { //New Race Type
                        //aSponsor = new Sponsor();
                        aSponsor = LoadSponsorFromForm();
                        db.Sponsors.Add(aSponsor);
                    }
                    else
                    { //Update actual Race Type
                        aSponsor = (from sponsors in db.Sponsors
                                    where sponsors.SponsorId == sponsorUsed.SponsorId
                                    select sponsors).FirstOrDefault();
                        if (aSponsor == null)
                        {
                            // The item wasn't found
                            ModelState.AddModelError("", String.Format("Sponsor con Id : {0} no encontrada", sponsorUsed.SponsorId));
                            X.Msg.Alert("Atención", "Sponsor no encontrado, grabación cancelada").Show();
                            return;
                        }
                        aSponsor.LogoURL = sponsorUsed.LogoURL;
                        aSponsor.ImageURL = sponsorUsed.ImageURL;
                        aSponsor.Nombre = txbxNombre.Text;
                        aSponsor.ContactPerson = txbxContacto.Text;
                        aSponsor.RegDate = Convert.ToDateTime(txbxRegDate.Text);
                        aSponsor.Activo = chbcActivo.Checked;
                        try
                        {
                            aSponsor.AportInicial = Convert.ToDecimal(txbxAportInicial.Text);
                        }
                        catch (Exception)
                        {
                            aSponsor.AportInicial = 0;
                        }
                        try
                        {
                            aSponsor.AportRecibida = Convert.ToDecimal(txbxAportRecibida.Text);
                        }
                        catch (Exception)
                        {
                            aSponsor.AportRecibida = 0;
                        }
                        aSponsor.CondOfertadas = txbxCondOfertadas.Text;
                        aSponsor.WebURL = txbxBlogURL.Text;
                        aSponsor.EMail = txbxEMail.Text;
                        aSponsor.Mobile = txbxMobile.Text;
                        aSponsor.Tlf = txbxTlf.Text;
                        aSponsor.Memo = txbxMemo.Text;
                        aSponsor.Address.Street = txbxStreet.Text;
                        aSponsor.Address.City = txbxCity.Text;
                        aSponsor.Address.Number = txbxNumber.Text;
                        aSponsor.Address.Country = txbxCountry.Text;
                        aSponsor.Address.PostalCode = txbxPostalCode.Text;

                        string aux = ReformatNumber(txbxLatitud.Text);
                        if (aux == null)
                            aSponsor.Latitud = 0;
                        else
                        {
                            aSponsor.Latitud = Convert.ToDouble(aux);
                        }

                        aux = ReformatNumber(txbxLongitud.Text);
                        if (aux == null)
                            aSponsor.Longitud = 0;
                        else
                        {
                            aSponsor.Longitud= Convert.ToDouble(aux);
                        }
                    }
                    db.SaveChanges();
                    LoadSponsorInForm(aSponsor);  //To update the ID (identity file)
                    sponsorUsed.CopySponsor(aSponsor);
                    oldSponsorUsed.CopySponsor(sponsorUsed);
                    this.StoreGPSponsors.DataBind();
                    X.Msg.Alert("Atención", "Datos de sponsor grabados.").Show();
                }
                btnBorrar.Enabled = true;
            }
            else
            {
                X.Msg.Alert("Atención", messageError).Show();
            }
        }
Ejemplo n.º 17
0
        public void DoSave()
        {
            bool sigue = true;
            int points = 0;
            int aSportIDSelected = 0;
            string messageError = null;

            //Verify name exists
            if (txbxName.Text == "")
            {
                sigue = false;
                messageError = "Falta el nombre del tipo de competición.";
            }

            //Verify points exists and are between 0 and 10.000
            if (sigue)
            {
                try
                {
                    points = Convert.ToInt32(txbxPuntos.Text);
                    if (points < 0 || points > 10000)
                    {
                        sigue = false;
                        messageError="Los puntos asignados deben ser un número entre 0 y 10.000";
                    }
                }
                catch (Exception)
                {
                    sigue = false;
                    messageError="Debes asignar un valor numérico entre 0 y 10.000 para los puntos.";
                }
            }

            //Verify is a SportID was choosed.
            if (sigue)
            {
                try
                {
                    aSportIDSelected = Convert.ToInt32(cbxDeportes.SelectedItem.Value);//Convert.ToInt32(txbxSportID.Text);
                    if (aSportIDSelected <= 0)
                    {
                        sigue = false;
                        messageError = "Escoje el tipo de deporte al que pertenece la competición.";
                    }
                }
                catch (Exception)
                {
                    sigue = false;
                    messageError = "Escoje el tipo de deporte al que pertenece la competición.";
                }
            }

            //Save if conditions are ok.
            if (sigue)
            {
                using (var db = new ClubSiteContext())
                {
                    RaceType aRacetype;
                    if (rtUsed.RaceTypeID == 0)
                    { //New Race Type
                        aRacetype = new RaceType();
                        aRacetype.Name = txbxName.Text;
                        aRacetype.Points = points;
                        aRacetype.SportID = aSportIDSelected;
                        aRacetype.Memo = txbxMemo.Text;
                        db.RaceTypes.Add(aRacetype);
                    }
                    else
                    { //Update actual Race Type
                        aRacetype = (from racetypes in db.RaceTypes
                                     where racetypes.RaceTypeID == rtUsed.RaceTypeID
                                     select racetypes).FirstOrDefault();
                        if (aRacetype == null)
                        {
                            // The item wasn't found
                            ModelState.AddModelError("", String.Format("Tipo de competición con Id : {0} no encontrada", rtUsed.RaceTypeID));
                            X.Msg.Alert("Atención","Tipo de competición no encontrada").Show();
                            return;
                        }
                        aRacetype.Name = txbxName.Text;
                        aRacetype.Points = points;
                        aRacetype.SportID = aSportIDSelected;
                        aRacetype.Memo = txbxMemo.Text;
                    }
                    db.SaveChanges();
                    LoadRaceTypeInForm(aRacetype);  //To update the ID (identity file)
                    rtUsed.CopyRaceType(aRacetype);
                    oldRtUsed.CopyRaceType(rtUsed);
                    this.Store1.DataBind();
                    X.Msg.Alert("Atención", "Nuevo tipo de competición grabada.").Show();
                }
                btnBorrar.Enabled = true;
            }
            else
            {
                X.Msg.Alert("Atención", messageError).Show();
            }
        }