예제 #1
0
 public bool SaveClass(ClassDetailsDTO dto)
 {
     using (HugoLANDContext context = new HugoLANDContext())
     {
         try
         {
             var currClass = new Classe()
             {
                 Id               = dto.Id,
                 NomClasse        = dto.ClassName,
                 Description      = dto.Description,
                 StatBaseStr      = dto.StatBaseStr,
                 StatBaseDex      = dto.StatBaseDex,
                 StatBaseReg      = dto.StatBaseReg,
                 StatBaseVitalite = dto.StatBaseVitality,
             };
             context.Entry(currClass).State = EntityState.Modified;
             context.SaveChanges();
             return(true);
         }
         catch
         {
             return(false);
         }
     }
 }
예제 #2
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            DialogResult dir = MessageBox.Show("Are you sure you want to delete this class?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

            switch (dir)
            {
            case DialogResult.Yes:
                ClassDetailsDTO deletedClass = new ClassDetailsDTO()
                {
                    Id = int.Parse(idTextBox.Text),
                };
                bool isSuccess = classServiceClient.DeleteClass(deletedClass);
                if (isSuccess)
                {
                    InitializeInfo();
                    if (!(classes.Count() == 0))
                    {
                        SetAllTextboxes(classes.First());
                    }
                    currentClassIndex = 0;
                }
                else
                {
                    MessageBox.Show("An error has occured while trying to delete the class", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                break;

            case DialogResult.No:
                break;

            default:
                break;
            }
        }
예제 #3
0
 public bool CreateClass(ClassDetailsDTO newClass, WorldDetailsDTO world)
 {
     try
     {
         using (HugoLANDContext context = new HugoLANDContext())
         {
             Monde monde  = context.Mondes.Find(world.ID);
             var   classe = new Classe()
             {
                 NomClasse        = newClass.ClassName,
                 Description      = newClass.Description,
                 StatBaseStr      = newClass.StatBaseStr,
                 StatBaseDex      = newClass.StatBaseDex,
                 StatBaseReg      = newClass.StatBaseReg,
                 StatBaseVitalite = newClass.StatBaseVitality,
                 Monde            = monde,
             };
             context.Entry(classe).State = EntityState.Added;
             context.SaveChanges();
             return(true);
         }
     }
     catch
     {
         return(false);
     }
 }
예제 #4
0
        private void btnModifiy_Click(object sender, EventArgs e)
        {
            List <string> errorsStats = VerifyInfo();

            if (errorsStats.Count > 0)
            {
                ClassDetailsDTO newClass = new ClassDetailsDTO()
                {
                    ClassName        = nomClasseTextBox.Text,
                    Description      = descriptionTextBox.Text,
                    StatBaseStr      = 0,
                    StatBaseDex      = 0,
                    StatBaseReg      = 0,
                    StatBaseVitality = 0
                };
                var result = createClassValidator.Validate(newClass);
                foreach (var item in result.Errors)
                {
                    errorsStats.Add(item.ErrorMessage);
                }

                MessageBox.Show(string.Join("\n", errorsStats), "Errors", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                ClassDetailsDTO modifiedClass = new ClassDetailsDTO()
                {
                    Id               = int.Parse(idTextBox.Text),
                    ClassName        = nomClasseTextBox.Text,
                    Description      = descriptionTextBox.Text,
                    StatBaseStr      = int.Parse(statBaseStrTextBox.Text),
                    StatBaseDex      = int.Parse(statBaseDexTextBox.Text),
                    StatBaseReg      = int.Parse(statBaseRegTextBox.Text),
                    StatBaseVitality = int.Parse(statBaseVitaliteTextBox.Text)
                };

                var result = createClassValidator.Validate(modifiedClass);

                if (!result.IsValid)
                {
                    MessageBox.Show(string.Join("\n", result.Errors.ToList()), "Errors", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                else
                {
                    bool isSuccess = classServiceClient.SaveClass(modifiedClass);
                    if (isSuccess)
                    {
                        MessageBox.Show("The class has been saved", "Success!", MessageBoxButtons.OK, MessageBoxIcon.None);
                        InitializeInfo();
                        SetAllTextboxes(classes[currentClassIndex]);
                    }
                    else
                    {
                        MessageBox.Show("An error has occured while trying to save the class", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
        }
예제 #5
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            List <string> errorsStats = VerifyInfo();

            if (errorsStats.Count > 0)
            {
                ClassDetailsDTO newClass = new ClassDetailsDTO()
                {
                    ClassName        = txtName.Text,
                    Description      = txtDescription.Text,
                    StatBaseStr      = 0,
                    StatBaseDex      = 0,
                    StatBaseReg      = 0,
                    StatBaseVitality = 0
                };
                var result = createClassValidator.Validate(newClass);
                foreach (var item in result.Errors)
                {
                    errorsStats.Add(item.ErrorMessage);
                }

                MessageBox.Show(string.Join("\n", errorsStats), "Errors", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                ClassDetailsDTO newClass = new ClassDetailsDTO()
                {
                    ClassName        = txtName.Text,
                    Description      = txtDescription.Text,
                    StatBaseStr      = int.Parse(txtStr.Text),
                    StatBaseDex      = int.Parse(txtDex.Text),
                    StatBaseReg      = int.Parse(txtReg.Text),
                    StatBaseVitality = int.Parse(txtVitality.Text)
                };

                var             result = createClassValidator.Validate(newClass);
                WorldDetailsDTO world  = worldsList.FirstOrDefault(w => w.Description == comboWorlds.Text);

                if (!result.IsValid)
                {
                    MessageBox.Show(string.Join("\n", result.Errors.ToList()), "Errors", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                else
                {
                    bool isSuccess = classServiceClient.CreateClass(newClass, world);
                    if (isSuccess)
                    {
                        MessageBox.Show("The class has been created", "Success!", MessageBoxButtons.OK, MessageBoxIcon.None);
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("An error has occured with the creation of the class", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
        }
예제 #6
0
 private void SetAllTextboxes(ClassDetailsDTO currentClass)
 {
     idTextBox.Text               = currentClass.Id.ToString();
     nomClasseTextBox.Text        = currentClass.ClassName;
     descriptionTextBox.Text      = currentClass.Description;
     statBaseStrTextBox.Text      = currentClass.StatBaseStr.ToString();
     statBaseDexTextBox.Text      = currentClass.StatBaseDex.ToString();
     statBaseRegTextBox.Text      = currentClass.StatBaseReg.ToString();
     statBaseVitaliteTextBox.Text = currentClass.StatBaseVitality.ToString();
 }
예제 #7
0
        public bool DeleteClass(ClassDetailsDTO dto)
        {
            try
            {
                using (HugoLANDContext context = new HugoLANDContext())
                {
                    var        delClass              = context.Classes.Find(dto.Id);
                    List <int> listDelHero           = new List <int>();
                    List <int> listDelHeroItems      = new List <int>();
                    List <int> listDelHeroInventaire = new List <int>();
                    foreach (Hero hero in delClass.Heros)
                    {
                        listDelHero.Add(hero.Id);
                        foreach (Item item in hero.Items)
                        {
                            listDelHeroItems.Add(item.Id);
                        }
                        foreach (InventaireHero inv in hero.InventaireHeroes)
                        {
                            listDelHeroInventaire.Add(inv.IdInventaireHero);
                        }
                    }
                    foreach (int id in listDelHeroItems)
                    {
                        context.Entry(context.Items.Find(id)).State = EntityState.Deleted;
                    }
                    foreach (int id in listDelHeroInventaire)
                    {
                        context.Entry(context.InventaireHeroes.Find(id)).State = EntityState.Deleted;
                    }
                    foreach (int id in listDelHero)
                    {
                        context.Entry(context.Heros.Find(id)).State = EntityState.Deleted;
                    }


                    context.Entry(delClass).State = EntityState.Deleted;
                    context.SaveChanges();
                    return(true);
                }
            }
            catch
            {
                return(false);
            }
        }