コード例 #1
0
        public async Task <bool> AddArtist(AddArtistDTO artistDTO)
        {
            Artist artist = _mapper.Map <Artist>(artistDTO);

            _db.Artists.Add(artist);
            return(await _db.SaveChangesAsync() > 0);
        }
コード例 #2
0
        public async Task <DataRespone <string> > Update(int id, AddArtistDTO artistDTO)
        {
            bool result = await _artistService.UpdateArtist(id, artistDTO);

            if (result)
            {
                return new DataRespone <string>()
                       {
                           Ok = true, data = "Artist " + id + " has been updated.", error = ""
                       }
            }
            ;
            throw new MyNotFoundException(HttpStatusCode.NotFound, "Artist have not found.");
        }
コード例 #3
0
        public async Task <DataRespone <string> > Add(AddArtistDTO artistDTO)
        {
            bool result = await _artistService.AddArtist(artistDTO);

            if (result)
            {
                return new DataRespone <string>()
                       {
                           Ok = true, data = "The new artist has added.", error = ""
                       }
            }
            ;
            return(new DataRespone <string>()
            {
                Ok = false, data = "Something went wrong.", error = "Adding an Artist was not success."
            });
        }
コード例 #4
0
        public async Task <bool> UpdateArtist(int id, AddArtistDTO artistDTO)
        {
            Artist artist = await _db.Artists.FindAsync(id);

            if (artist != null)
            {
                Artist artist1 = _mapper.Map <Artist>(artistDTO);

                artist.Name       = artist1.Name;
                artist.DayOfBirth = artist1.DayOfBirth;
                artist.Education  = artist1.Education;
                artist.Hometown   = artist1.Hometown;

                await _db.SaveChangesAsync();

                return(true);
            }
            return(false);
        }