Ejemplo n.º 1
0
        public bool CreateOrUpdate(ProfilCreate profilCreate)
        {
            var    profil   = _profileRepository.List().FirstOrDefault();
            string fileName = "";

            if (profil == null)
            {
                _fileService.Clear("profile");
                fileName = _fileService.Copy(profilCreate.ImgPath, "profile");
                if (fileName != null)
                {
                    profilCreate.ImgPath = fileName;
                }

                return(_profileRepository.Save(new Profil(profilCreate)));
            }

            if (!profilCreate.ImgPath.Equals(profil.ImgPath))
            {
                _fileService.Clear("profile");
                fileName = _fileService.Copy(profilCreate.ImgPath, "profile");
                if (fileName != null)
                {
                    profilCreate.ImgPath = fileName;
                }
            }

            return(_profileRepository.Update(profil.Update(profilCreate)));
        }
Ejemplo n.º 2
0
        public Profil(ProfilCreate profilCreate)
        {
            Description = profilCreate.Description;
            Title       = profilCreate.Title;
            Header      = profilCreate.Header;
            ImgPath     = profilCreate.ImgPath;

            profilCreate.Options.ToList().ForEach(p => {
                Options.Add(new ProfileOption()
                {
                    Title = p.Title,
                    Value = p.Value
                });
            });
        }
Ejemplo n.º 3
0
        public Profil Update(ProfilCreate profilCreate)
        {
            Description = profilCreate.Description;
            Title       = profilCreate.Title;
            Header      = profilCreate.Header;
            ImgPath     = profilCreate.ImgPath;

            Options.Clear();
            profilCreate.Options.ToList().ForEach(p => {
                Options.Add(new ProfileOption()
                {
                    Title = p.Title,
                    Value = p.Value
                });
            });

            return(this);
        }
        public IActionResult AddProfile([FromBody] ProfilCreate profilCreate)
        {
            if (profilCreate == null)
            {
                throw new ApiException("Błąd danych parametru");
            }

            if (!ModelState.IsValid)
            {
                throw new ApiValidationException("Walidacja");
            }

            if (!this._profileService.CreateOrUpdate(profilCreate))
            {
                throw new ApiException("Bład wykonano akcji dodania profilu");
            }

            return(new ResponseObjectResult("Pomyślnie wykonano akcji dodania profilu"));
        }