Пример #1
0
        private void BtnUploadPicture_Click(object sender, EventArgs e)
        {
            var openFileDialog = new OpenFileDialog
            {
                InitialDirectory = $@"C:\Users\{Environment.UserName}\Bilder",
                Filter           = @"Image files (*.jpg, *.jpeg, *.jpe, *.jfif, *.png) | *.jpg; *.jpeg; *.jpe; *.jfif; *.png",
            };

            try
            {
                openFileDialog.ShowDialog();
            }
            catch
            {
                openFileDialog.InitialDirectory = "";
                openFileDialog.ShowDialog();
            }
            var pathToPic = openFileDialog.FileName;
            var image     = Image.FromFile(pathToPic);

            PbImage.Image  = image;
            _group.Picture = ImageByteConverter.ImageToBytes(image);
        }
Пример #2
0
        private async void BtnSave_Click(object sender, EventArgs e)
        {
            _group.Picture     = ImageByteConverter.ImageToBytes(PbImage.Image);
            _group.Description = TbDescription.Text;
            _group.Name        = TbName.Text;
            _group.CreateDate  = DateTime.Now;
            var db = new DataBase();

            if (_group.Id == 0)
            {
                db.Groups.Add(_group);
                var node = new GroupToOrganization
                {
                    CreateDate     = DateTime.Now,
                    Group          = _group,
                    Deleted        = false,
                    OrganizationId = ((Organization)CbOrganizations.SelectedItem).Id
                };
                db.GroupToOrganizationNode.Add(node);
            }
            else
            {
                db.Entry(_group).State = EntityState.Modified;
                var oldGroupNode =
                    await db.GroupToOrganizationNode
                    .FirstOrDefaultAsync(d => !d.Deleted &&
                                         d.GroupId == _group.Id &&
                                         d.OrganizationId == ((Organization)CbOrganizations.SelectedItem).Id);

                if (oldGroupNode != null)
                {
                    oldGroupNode.Deleted = CheckOldLink.Checked;
                    var newGroupNode = new GroupToOrganization
                    {
                        CreateDate     = DateTime.Now,
                        GroupId        = _group.Id,
                        Deleted        = false,
                        OrganizationId = ((Organization)CbOrganizations.SelectedItem).Id
                    };
                    db.GroupToOrganizationNode.Add(newGroupNode);
                }
            }
            if (_gotEmails)
            {
                foreach (var email in _emails)
                {
                    if (email.GroupNode.Any(d => !d.Deleted && d.GroupId == _group.Id))
                    {
                        continue;
                    }
                    var emailToGroupNode = new EmailToGroup
                    {
                        EmailId    = email.Id,
                        CreateDate = DateTime.Now,
                        Deleted    = false,
                        GroupId    = _group.Id
                    };
                    db.EmailToGroupNode.Add(emailToGroupNode);
                }
                db.Emails.AddRange(_emails);
            }

            if (_gotHomepage)
            {
                foreach (var homepage in _homepages)
                {
                    if (homepage.GroupNode.Any(d => !d.Deleted && d.GroupId == _group.Id))
                    {
                        continue;
                    }
                    var homepageToGroupNode = new HomepageToGroup
                    {
                        HomepageId = homepage.Id,
                        CreateDate = DateTime.Now,
                        Deleted    = false,
                        GroupId    = _group.Id
                    };
                    db.HomepageToGroupNode.Add(homepageToGroupNode);
                }
                db.Homepages.AddRange(_homepages);
            }

            if (_gotPhone)
            {
                foreach (var number in _phoneNumbers)
                {
                    if (number.GroupNode.Any(d => !d.Deleted && d.GroupId == _group.Id))
                    {
                        continue;
                    }
                    var phoneToGroupNode = new PhoneToGroup
                    {
                        PhoneNumberId = number.Id,
                        CreateDate    = DateTime.Now,
                        Deleted       = false,
                        GroupId       = _group.Id
                    };
                    db.PhoneToGroupNode.Add(phoneToGroupNode);
                }
                db.PhoneNumbers.AddRange(_phoneNumbers);
            }

            await db.SaveChangesAsync();

            Close();
        }