Beispiel #1
0
        private void UpdateData()
        {
            _user.Name     = NameField.Text;
            _user.LastName = SurNameField.Text;
            _user.RegMail  = EmailField.Text;
            _user.Bio      = BioField.Text;
            _user.Classes.Clear();
            _user.Skills.Clear();
            if (_imagePath != _user.PicturePath)
            {
                if (File.Exists(openFileDialog1.FileName))
                {
                    Image Img = new Bitmap(openFileDialog1.FileName);
                    Img.Save(@"Pictures\" + openFileDialog1.SafeFileName);
                    _user.PicturePath = openFileDialog1.SafeFileName;
                }
            }
            for (int i = 0; i < SkillsList.Items.Count; i++)
            {
                Skills skill;
                var    check = TeamBuildingEntities.Skills.ToList().Where(k => k.SklName == SkillsList.Items[i].ToString());
                if (check.ToList().Count > 0)
                {
                    _user.Skills.Add(check.ToList()[0]);
                }
                else
                {
                    TeamBuildingEntities.Skills.Add(new Skills()
                    {
                        Projects = new List <Projects>(),
                        SklId    = TeamBuildingEntities.Skills.Count() + 1,
                        SklName  = SkillsList.Items[i].ToString(),
                        Users    = new List <Users>()
                    });
                    //TeamBuildingEntities.SaveChanges();
                    _user.Skills.Add(TeamBuildingEntities.Skills.ToList().Last());
                }
            }

            for (int i = 0; i < ClassList.Items.Count; i++)
            {
                if (ClassList.GetItemChecked(i))
                {
                    _user.Classes.Add(TeamBuildingEntities.Classes.ToList()[i]);
                }
            }
            //TeamBuildingEntities.Entry(TeamBuildingEntities.Users).State=EntityState.Modified;
            TeamBuildingEntities.SaveChanges();
        }
Beispiel #2
0
        private Projects CreateBaseForProject()
        {
            try
            {
                UsersList = new ObservableCollection <Users>(TeamBuildingEntities.Users);

                int projectId;
                if (ExistedProject == null)
                {
                    projectId =
                        TeamBuildingEntities.Projects.ToList()[TeamBuildingEntities.Projects.Count() - 1].PrjtId + 1;
                }
                else
                {
                    projectId = ExistedProject.PrjtId;
                }

                if (!File.Exists(openFileDialog1.FileName) && ExistedProject == null)
                {
                    _imagePath = "default.jpg";
                }

                _newProject = new Projects()
                {
                    PrjtId          = projectId,
                    PrjtName        = NameField.Text,
                    PrjtDescription = DescriptionField.Text,
                    PrjtCreated     =
                        (ExistedProject == null) ? Convert.ToDateTime(DateTime.Today) : ExistedProject.PrjtCreated,
                    PrjtImagePath = _imagePath,
                    PrjtCreatedBy =
                        (ExistedProject == null)
                            ? UsersList[StartUp.SelectedUser - 1].UsrId
                            : ExistedProject.PrjtCreatedBy,
                    PjrtLikeCounter = (ExistedProject == null) ? 0 : ExistedProject.PjrtLikeCounter
                };

                _newProject.Users2.Clear();
                _newProject.Users2.Add(UsersList[StartUp.SelectedUser - 1]);

                if (File.Exists(openFileDialog1.FileName) ||
                    ExistedProject != null && ExistedProject.PrjtImagePath != _imagePath)
                {
                    Image Img = new Bitmap(openFileDialog1.FileName);
                    Img.Save(@"Pictures\" + openFileDialog1.SafeFileName);
                }

                if (ExistedProject != null)
                {
                    ExistedProject.PrjtClasses.Clear();
                    ExistedProject.Skills.Clear();
                }

                for (int i = 0; i < SkillList.Items.Count; i++)
                {
                    Skills skill;
                    var    check = TeamBuildingEntities.Skills.ToList().Where(k => k.SklName == SkillList.Items[i].ToString());
                    if (check.ToList().Count > 0)
                    {
                        _newProject.Skills.Add(check.ToList()[0]);
                    }
                    else
                    {
                        TeamBuildingEntities.Skills.Add(new Skills()
                        {
                            Projects = new List <Projects>(),
                            SklId    = TeamBuildingEntities.Skills.Count() + 1,
                            SklName  = SkillList.Items[i].ToString(),
                            Users    = new List <Users>()
                        });
                        TeamBuildingEntities.SaveChanges();
                        _newProject.Skills.Add(TeamBuildingEntities.Skills.ToList().Last());
                    }
                }

                for (int i = 0; i < ClassList.Items.Count; i++)
                {
                    if (ClassList.GetItemChecked(i))
                    {
                        _newProject.PrjtClasses.Add(new PrjtClasses()
                        {
                            ClClassId      = i,
                            ClPrjtId       = _newProject.PrjtId,
                            ClPeopleNeeded = "1",
                            Classes        = TeamBuildingEntities.Classes.ToList()[i],
                            Projects       = _newProject
                        });
                    }
                }
            }

            catch (Exception exception)
            {
                MessageBox.Show(exception.ToString());
            }

            return(_newProject);
        }