Esempio n. 1
0
        public Person ChangePersonAvatar(long personID, string avatar)
        {
            var person = this.GetPerson(personID);

            if (person == null)
            {
                throw new CustomNotFoundException($"Person with ID={personID} not found");
            }

            if (String.IsNullOrWhiteSpace(avatar))
            {
                return(person);
            }

            Avatar avtr = null;

            if (avatar.StartsWith("data:", CommonService.StringComparison))
            {
                avtr = this.SaveAvatar(Imager.CreateFromDataUrl(avatar).Save());
            }
            else
            {
                avtr = this.UnitOfWork.FindByCode <Avatar>(avatar);
            }

            person.ChangeAvatar(avtr);

            this.UnitOfWork.PersonRepository.Update(person);

            this.SaveChanges();

            return(person);
        }