Exemple #1
0
 public void Load(ArtistDto artist)
 {
     //если объект не существует выходим
     if (artist == null)
     {
         return;
     }
     //сохраняем id художника
     _id = artist.Id;
     //заполняем визуальные компоненты для отображения данных
     tbName.Text  = artist.Name;
     tbBirth.Text = artist.BirthYear.ToString();
     if (artist.DeceaseYear.HasValue)
     {
         tbDeath.Text = artist.DeceaseYear.Value.ToString();
     }
     if (artist.Nation != null)
     {
         foreach (NationDto Nat in Nationalities)
         {
             if (artist.Nation.NationID == Nat.NationID)
             {
                 this.cbNationality.SelectedItem = Nat;
                 break;
             }
         }
     }
 }
Exemple #2
0
        public Response <ArtistDto> Create(ArtistDto newObject)
        {
            try
            {
                if (newObject != null && ValidateName(newObject))
                {
                    Response <int> dataResponse = dal.Insert(newObject);
                    newObject.Id = dataResponse.Data;

                    return(new Response <ArtistDto>(dataResponse.Status, dataResponse.Message, newObject));
                }
                return(new Response <ArtistDto>(false, "Artist Null or Artist Name isn't valid.", null));
            }
            catch (Exception e)
            {
                if (e.InnerException == null)
                {
                    return(new Response <ArtistDto>(false, "Somethig was wrong. Exception: " + e.Message, null));
                }
                else
                {
                    return(new Response <ArtistDto>(false, "Somethig was wrong. Exception: " + e.InnerException.InnerException.Message, null));
                }
            }
        }
Exemple #3
0
 public Response <ArtistDto> FindById(int id)
 {
     if (id <= 0)
     {
         return(new Response <ArtistDto>(false, "Id must be grater than 0", null));
     }
     try
     {
         ArtistDto response = new ArtistDto();
         using (musicDBEntities db = new musicDBEntities())
         {
             Artist artist = db.Artist.Find(id);
             response.Id   = artist.artist_id;
             response.Name = artist.name;
         }
         return(new Response <ArtistDto>(true, "Artist was found", response));
     }
     catch (Exception e)
     {
         if (e.InnerException == null)
         {
             return(new Response <ArtistDto>(false, "Somethig was wrong. Exception: " + e.Message, null));
         }
         else
         {
             return(new Response <ArtistDto>(false, "Somethig was wrong. Exception: " + e.InnerException.InnerException.Message, null));
         }
     }
 }
Exemple #4
0
        public Response <IEnumerable <ArtistDto> > SelectAll()
        {
            List <ArtistDto> response = new List <ArtistDto>();

            try
            {
                using (musicDBEntities db = new musicDBEntities())
                {
                    List <Artist> artists = db.Artist.ToList();

                    foreach (Artist artist in artists)
                    {
                        ArtistDto aux = new ArtistDto();
                        aux.Id   = artist.artist_id;
                        aux.Name = artist.name;
                        response.Add(aux);
                    }
                }
                return(new Response <IEnumerable <ArtistDto> >(true, response.Count + " artists found", response));
            }
            catch (Exception e)
            {
                if (e.InnerException == null)
                {
                    return(new Response <IEnumerable <ArtistDto> >(false, "Somethig was wrong. Exception: " + e.Message, response));
                }
                else
                {
                    return(new Response <IEnumerable <ArtistDto> >(false, "Somethig was wrong. Exception: " + e.InnerException.InnerException.Message, response));
                }
            }
        }
        public async Task <IEnumerable <ArtistDto> > SearchSpotifyArtists(string keyword)
        {
            var auth  = new CredentialsAuth(ClientId, SecretId);
            var token = await auth.GetToken();

            var api = new SpotifyWebAPI()
            {
                TokenType   = token.TokenType,
                AccessToken = token.AccessToken
            };

            var searchItem = await api.SearchItemsAsync(keyword, SearchType.Artist);

            var artistsToReturn = new List <ArtistDto>();

            foreach (var artist in searchItem.Artists.Items)
            {
                var artistToReturn = new ArtistDto
                {
                    Name     = artist.Name,
                    Id       = artist.Id,
                    PhotoUrl = artist.Images.Count > 0 ? artist.Images[0].Url : null
                };
                artistsToReturn.Add(artistToReturn);
            }

            return(artistsToReturn);
        }
        public async Task <IEnumerable <ArtistDto> > GetSpotifyArtists(List <string> artistsIdToGet)
        {
            var auth  = new CredentialsAuth(ClientId, SecretId);
            var token = await auth.GetToken();

            var api = new SpotifyWebAPI()
            {
                TokenType   = token.TokenType,
                AccessToken = token.AccessToken
            };

            var artistsFromSpotify = await api.GetSeveralArtistsAsync(artistsIdToGet);

            var artistsToReturn = new List <ArtistDto>();

            foreach (var artist in artistsFromSpotify.Artists)
            {
                var artistToReturn = new ArtistDto
                {
                    Name = artist.Name, Id = artist.Id, PhotoUrl = artist.Images[0].Url
                };
                artistsToReturn.Add(artistToReturn);
            }

            return(artistsToReturn);
        }
Exemple #7
0
        public Response <int> Insert(ArtistDto newObject)
        {
            if (newObject == null)
            {
                return(new Response <int>(false, "Artist cannot be null", -1));
            }

            Artist artist = new Artist();

            artist.name = newObject.Name;

            try
            {
                using (musicDBEntities db = new musicDBEntities())
                {
                    db.Artist.Add(artist);
                    db.SaveChanges();
                }
                return(new Response <int>(true, "Artist was inserted in DB", artist.artist_id));
            }
            catch (Exception e)
            {
                if (e.InnerException == null)
                {
                    return(new Response <int>(false, "Somethig was wrong. Exception: " + e.Message, -1));
                }
                else
                {
                    return(new Response <int>(false, "Somethig was wrong. Exception: " + e.InnerException.InnerException.Message, -1));
                }
            }
        }
Exemple #8
0
        public async Task <BaseResponse <ArtistDto> > Insert(ArtistImageModel artistImageModel)
        {
            //TODO
            BaseResponse <ArtistDto> baseResponse = new BaseResponse <ArtistDto>();
            Files files = new Files
            {
                ImageFile = artistImageModel.File
            };
            var file = await _filesService.Insert(files);

            Artist artist = new Artist
            {
                FileId = file.Id,
                Gender = artistImageModel.Gender,
                Info   = artistImageModel.Info,
                Name   = artistImageModel.Name
            };
            var result = await _artistRepository.Insert(artist);

            var fileDto = _mapper.Map <FilesDto>(file);
            //new FilesDto { Id = file.Id, Path = file.Path };
            var artistDto = new ArtistDto {
                File = fileDto, Gender = result.Gender, Id = result.Id, Info = result.Info, Name = result.Name
            };

            baseResponse.Result = artistDto;
            return(baseResponse);
        }
        public void Load(ArtistDto artist)
        {
            if (artist == null)
            {
                return;
            }

            _id = artist.Id;

            tbName.Text  = artist.Name;
            tbBirth.Text = artist.BirthYear.ToString();
            if (artist.DeceaseYear.HasValue)
            {
                tbDeath.Text = artist.DeceaseYear.Value.ToString();
            }

            if (artist.Nation != null)
            {
                foreach (NationDto nation in Nationalities)
                {
                    if (artist.Nation.Id == nation.Id)
                    {
                        this.cbNationality.SelectedItem = nation;
                        break;
                    }
                }
            }
        }
Exemple #10
0
        public async Task <IHttpActionResult> UpdateArtist(int id, ArtistDto artistDto)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest());
                }

                var artistInDb = await _unitOfWork.Artists.GetByIdAsync(id);

                if (artistInDb == null)
                {
                    return(Content(HttpStatusCode.NotFound, string.Format("Artist with Id: {0} could not be found", id)));
                }

                Mapper.Map(artistDto, artistInDb);

                //Save
                _unitOfWork.Complete();

                return(Ok());
            }
            catch (Exception ex)
            {
                return(Content(HttpStatusCode.BadRequest, string.Format("Artist could not be Updated: {0}", ex.Message)));
            }
        }
Exemple #11
0
        public bool SaveArtistInfo(ArtistDto artist)
        {
            Contract.Requires(artist != null);
            Contract.Requires(!string.IsNullOrEmpty(artist.Name));

            return(default(bool));
        }
        public async Task Post(ArtistDto model)
        {
            var mapped = _mapper.Map <Artist>(model);

            _repository.Artist.Create(mapped);
            await _repository.SaveAsync();
        }
        public void Add(ArtistDto artist)
        {
            int max = Artists.Keys.Count == 0 ? 1 : Artists.Keys.Max(p => p) + 1;

            artist.Id = max;
            Artists.Add(max, artist);
        }
Exemple #14
0
        public async Task <ArtistDto> CreateArtistAsync([FromBody] ArtistDto artistDto)
        {
            _logger?.LogDebug("'{0}' has been invoked", MethodBase.GetCurrentMethod().DeclaringType);
            var response = new ArtistDto();

            if (ModelState.IsValid)
            {
                try
                {
                    _logger?.LogInformation("The CreateArtistAsync have been retrieved successfully.");

                    var artist = await _albumRepository.CreateArtistAsync(_mapper.Map <Artist>(artistDto));

                    return(_mapper.Map <ArtistDto>(artist));
                }

                catch (Exception ex)
                {
                    _logger?.LogCritical("There was an error on '{0}' invocation: {1}", MethodBase.GetCurrentMethod().DeclaringType, ex);
                    return(response = new ArtistDto {
                        ErrorMessage = new string[] { ex.Message }
                    });
                }
            }
            else
            {
                return response = new ArtistDto {
                           ErrorMessage = new string[] { "ModelState is not valid: " + ModelState.ToString() }
                }
            };
        }
 public void Update(ArtistDto artist)
 {
     if (Artists.ContainsKey(artist.Id))
     {
         Artists[artist.Id] = artist;
     }
 }
Exemple #16
0
 public int Update(ArtistDto value)
 {
     using (KivoDbContext context = new KivoDbContext(Configuration.GetConnectionString("DefaultConnection")))
     {
         return(context.Artist.Udpate(value.ConvertToArtist()));
     }
 }
Exemple #17
0
        public async Task <ArtistDto> CreateAsync(ArtistDto item)
        {
            var result = _context.Artist.Add(ArtistConverter.Convert(item));
            await _context.SaveChangesAsync();

            return(ArtistConverter.Convert(result.Entity));
        }
        public async Task <IActionResult> AddNew(ArtistDto entityDto)
        {
            _dbContext.Connection.Open();
            using (var transaction = _dbContext.Connection.BeginTransaction())
            {
                try
                {
                    _dbContext.Database.UseTransaction(transaction as DbTransaction);
                    bool GenresExists = await _dbContext.Artists.AnyAsync(a => a.Name == entityDto.Name);

                    if (GenresExists)
                    {
                        return(BadRequest(new { msg = "Artist Already Exists" }));
                    }


                    var addGenresQuery = $"INSERT INTO artists(Name) VALUES('{entityDto.Name}');SELECT last_insert_rowid()";
                    var dataId         = await _writeDbConnection.QuerySingleAsync <int>(addGenresQuery, transaction : transaction);

                    if (dataId == 0)
                    {
                        return(BadRequest(new { msg = "Artist could not be inserted" }));
                    }

                    await _dbContext.SaveChangesAsync(default);
Exemple #19
0
 public Artist FromArtistDto(ArtistDto artistDto)
 {
     return(new Artist
     {
         Id = artistDto.Id,
         Name = artistDto.Name
     });
 }
Exemple #20
0
        public async Task UpdateArtist(ArtistDto dto)
        {
            var artist = _mapper.Map <Artist>(dto);

            _unitOfWork.Artists.Edit(artist);

            await _unitOfWork.CommitAsync();
        }
Exemple #21
0
        public async Task <ArtistDto> Update(ArtistDto item)
        {
            Artist artist = _mapper.Map <ArtistDto, Artist>(item);

            artist = await _database.ArtistRepository.Update(artist);

            return(_mapper.Map <Artist, ArtistDto>(artist));
        }
Exemple #22
0
 public static Artist Convert(ArtistDto artist)
 {
     return(new Artist
     {
         Name = artist.Name,
         Id = artist.Id
     });
 }
Exemple #23
0
        private static AbstractArtistDto Add(string pName, string pThumbnail)
        {
            AbstractArtistDto ar = new ArtistDto();

            ar.Name      = pName;
            ar.Thumbnail = pThumbnail;
            return(ar);
        }
Exemple #24
0
        public async Task <IActionResult> PostArtist(ArtistDto artistDto)
        {
            var artist = _mapper.Map <Artist>(artistDto);

            await _artistRepository.InsertArtist(artist);

            return(Ok(artist));
        }
Exemple #25
0
        private async Task GetFullInfoAndAddToDatabaseIfNeeded(List <ArtistDto> artists)
        {
            IEnumerable <ArtistDto> artistsToAdd = GetArtistsWhichNotInDatabase(artists);

            foreach (var artist in artistsToAdd)
            {
                ArtistDto artistToAdd = await GetFullInfoAboutArtist(artist);
                await Create(artistToAdd);
            }
        }
Exemple #26
0
        public async Task <ArtistDto> CreateArtist(ArtistDto dto)
        {
            var artist = _mapper.Map <ArtistDto, Artist>(dto);

            await _unitOfWork.Artists.AddAsync(artist);

            await _unitOfWork.CommitAsync();

            return(dto);
        }
Exemple #27
0
 public void CreateArtist(ArtistDto artistDto)
 {
     using (var transaction = _artistRepository.unitOfWork.BeginTransaction(3))
     {
         _artistRepository.Add(ArtistFactory.CreateArtist(artistDto.DisplayName,
                                                          artistDto.Firstname,
                                                          artistDto.Lastname,
                                                          artistDto.ArtistDetails));
     }
 }
Exemple #28
0
        public async Task <BaseResponse <string> > Delete(ArtistDto artist)
        {
            BaseResponse <string> baseResponse = new BaseResponse <string>();
            await _filesService.Delete(artist.File);

            var isDeleted = await _artistRepository.DeleteById(artist.Id);

            baseResponse.Result = isDeleted > 0 ? "Success Delete" : null;
            return(baseResponse);
        }
Exemple #29
0
        public async Task <bool> UpdateAsync(ArtistDto item)
        {
            if (item == null)
            {
                return(false);
            }
            _context.Artist.Update(ArtistConverter.Convert(item));
            await _context.SaveChangesAsync();

            return(true);
        }
Exemple #30
0
        public ActionResult <Artist> PostArtist(ArtistDto artistDto)
        {
            var result = _artistService.Add(artistDto);

            if (!result.Success)
            {
                return(BadRequest(result));
            }

            return(CreatedAtAction("GetArtist", new { id = result.ResultData.Id }, artistDto));
        }
        // PUT api/Artists/5
        public HttpResponseMessage PutArtist(int id, ArtistDto artist)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            var artistToUpdate = db.Artists.FirstOrDefault(a => a.ArtistId == id);

            if (artistToUpdate != null && artist != null)
            {
                artistToUpdate.UpdateWith(new Artist
                {
                    ArtistName = artist.ArtistName,
                    Country = artist.Country,
                    DateOfBirth = artist.DateOfBirth
                });
            }
            else
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

            db.Entry(artistToUpdate).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex);
            }

            return Request.CreateResponse(HttpStatusCode.OK);
        }
        // POST api/Artists
        public HttpResponseMessage PostArtist(ArtistDto artist)
        {
            if (ModelState.IsValid)
            {
                var newArtist = new Artist
                {
                    ArtistName = artist.ArtistName,
                    Country = artist.Country,
                    DateOfBirth = artist.DateOfBirth
                };

                db.Artists.Add(newArtist);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, newArtist);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = newArtist.ArtistId }));
                return response;
            }
            else
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
        }