Ejemplo n.º 1
0
        protected void btnNewIcon_Click(object sender, EventArgs e)
        {
            _master.SetLabMessage(Color.Empty, string.Empty);

            var extension = Path.GetExtension(btnChooseIcon.FileName);
            if (extension == null)
            {
                _master.SetLabMessage(ErrorColor, "Profile_NotImage");
                return;
            }

            if (!btnChooseIcon.HasFile || (extension.ToLower() != ".jpg" && extension.ToLower() != ".jpeg"))
            {
                _master.SetLabMessage(ErrorColor, !btnChooseIcon.HasFile ? "Profile_NotImage" : "Profile_NotJpg");
                return;
            }

            if (btnChooseIcon.FileBytes.Length == 0)
            {
                _master.SetLabMessage(ErrorColor, "Profile_NotImage");
                return;
            }

            var user = _userGroup.GetUser();
            var person = _dbPersonRepository.GetAll().FirstOrDefault(p => p.Login == user.UserName) ?? new Person
            {
                Login = user.UserName,
                Name = "",
                SecondName = ""
            };

            var image = _imageService.ByteArrayToImage(btnChooseIcon.FileBytes);
            var newImage = (Image) (new Bitmap(image, _imageService.GetSize(image.Size, 500)));

            var updatedPerson = new Person
            {
                Login = person.Login,
                Name = person.Name,
                SecondName = person.SecondName,
                Icon = _imageService.ImageToByteArray(newImage)
            };

            _master.SetLabMessage(Color.Empty, string.Empty);
            if (_dbPersonRepository.AddOrUpdate(updatedPerson))
            {
                _master.SetLabMessage(SuccessColor, "Profile_IconWasChanged");
                Logger.Log.Info(string.Format("Icon successfully changed for user - {0}.", user.UserName));
            }
            else _master.SetLabMessage(ErrorColor, "Profile_IconWasNotChanged");

            RefreshIcon(updatedPerson.Icon);
        }
 public bool AddOrUpdate(Person person)
 {
     _context.PersonTable.AddOrUpdate(person);
     return _context.SaveChanges() > 0;
 }
Ejemplo n.º 3
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            var user = _userGroup.GetUser();

            var person = _dbPersonRepository.GetAll().FirstOrDefault(p => p.Login == user.UserName);
            if(person == null) return;

            var updatedPerson = new Person
            {
                Login = person.Login,
                Name = tbName.Text,
                SecondName = tbSecondName.Text,
                Icon = person.Icon
            };

            if (!_dbPersonRepository.AddOrUpdate(updatedPerson))
            {
                _master.SetLabMessage(ErrorColor, "Profile_IconWasNotChanged");
            }
            else
            {
                _master.SetLabMessage(SuccessColor, "Profile_PersonalDataChanged");
                Logger.Log.Info(string.Format("Personal data successfully commited for user - {0}.", user.UserName));
            }

            RefereshUser();
        }