Example #1
0
        public async Task <ArtistVm> Handle(CreateArtist request, CancellationToken cancellationToken)
        {
            var    artist = new Artist(Guid.NewGuid(), request.Name, request.Age, request.Description);
            string imageUrl;

            if (request.Photo?.HasValue() == true)
            {
                if (!string.IsNullOrEmpty(artist.Photo))
                {
                    await _fileUtils.RemoveByUrlAsync(artist.Photo);
                }

                var fileName = $"artists/{Guid.NewGuid()}{request.Photo.Name.GetExtension()}";

                imageUrl = await _fileUtils.UploadAsync(request.Photo, fileName);

                if (imageUrl.IsNull())
                {
                    throw new Exception("Erro ao Importar o poster");
                }
            }
            else
            {
                imageUrl = artist.Photo;
            }
            artist.Photo = imageUrl;

            await _artistRepository.AddAsync(artist);

            return(artist.ToVm());
        }
Example #2
0
        //Path: /api/Artist/CreateArtist
        public HttpResponseMessage CreateArtist(CreateArtist createArtistRequest)
        {
            // Trace Log
            File.AppendAllText(SuiteWrapper.traceLogPath, Environment.NewLine + Environment.NewLine);
            SuiteWrapper.WriteTraceLog("Called 'CreateArtist' with request :" + JsonConvert.SerializeObject(createArtistRequest));
            CreateArtistResponse createArtistResponse = new CreateArtistResponse();

            string outputMessage = string.Empty;

            if (!SuiteWrapper.ValidateRequest(createArtistRequest, out outputMessage))
            {
                //Trace Log
                SuiteWrapper.WriteTraceLog("Exception while validating request for " + JsonConvert.SerializeObject(createArtistRequest) + " is : " + outputMessage);
                return(Request.CreateResponse(HttpStatusCode.NotAcceptable, outputMessage));;
            }

            try
            {
                using (PundolesEntities context = new PundolesEntities())
                {
                    artist artistObject = new artist();
                    artistObject.name            = createArtistRequest.name;
                    artistObject.description     = createArtistRequest.description;
                    artistObject.year_of_birth_c = createArtistRequest.year_of_birth_c;
                    artistObject.year_of_death_c = createArtistRequest.year_of_death_c;
                    artistObject.status          = createArtistRequest.status;
                    artistObject.created_date    = DateTime.Now;
                    artistObject.modified_date   = DateTime.Now;
                    artistObject.createdby_id    = createArtistRequest.createdby_id;
                    artistObject.modifiedby_id   = createArtistRequest.createdby_id;
                    context.artists.Add(artistObject);

                    context.SaveChanges();

                    createArtistResponse.id     = artistObject.id;
                    createArtistResponse.status = "Success";

                    SuiteWrapper.WriteTraceLog("user is successfully created with response :" + JsonConvert.SerializeObject(createArtistResponse));
                    return(Request.CreateResponse(HttpStatusCode.OK, createArtistResponse));
                }
            }
            catch (Exception ex)
            {
                createArtistResponse.id     = null;
                createArtistResponse.status = ex.Message.ToString();

                SuiteWrapper.WriteTraceLog("Exception while creating artist is : " + ex.Message.ToString());
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, JsonConvert.SerializeObject(createArtistResponse)));
            }
        }
Example #3
0
        // PUT: api/Artist/5
        public string Put(string id, [FromBody] CreateArtist value)
        {
            SqlCommand cmd = new SqlCommand();

            conn.Connectdb("update Artist set Name_artist=@Name_artist, Nationality=@Nationality where Id_artist='" + id + "'", cmd);
            cmd.Parameters.AddWithValue("@Name_artist", value.Name_artist);
            cmd.Parameters.AddWithValue("@Nationality", value.Nationality);
            int result = cmd.ExecuteNonQuery();

            if (result > 0)
            {
                return("mise à jour réussie");
            }
            else
            {
                return("echec mise à jour");
            }
        }
Example #4
0
        // POST: api/Artist
        public string Post([FromBody] CreateArtist value)
        {
            SqlCommand cmd = new SqlCommand();

            conn.Connectdb("insert into Artist(Id_artist, Name_artist, Nationality) values(@Id_artist, @Name_artist, @Nationality)", cmd);
            cmd.Parameters.AddWithValue("@Id_artist", value.Id_artist);
            cmd.Parameters.AddWithValue("@Name_artist", value.Name_artist);
            cmd.Parameters.AddWithValue("@Nationality", value.Nationality);
            int result = cmd.ExecuteNonQuery();

            if (result > 0)
            {
                return("insertion réussie");
            }
            else
            {
                return("echec insertion");
            }
        }
        public Artist Insert(CreateArtist value)
        {
            using (var tran = db.Database.BeginTransaction(System.Data.IsolationLevel.RepeatableRead))
            {
                if (db.Artists.Any(t => EF.Functions.Like(t.Name, value.Name)))
                {
                    throw new ArgumentException("name must be unique");
                }

                var toInsert = new DbArtist()
                {
                    Name = value.Name
                };
                db.Artists.Add(toInsert);

                db.SaveChanges();
                tran.Commit();

                return(ToModel(toInsert));
            }
        }
Example #6
0
 public bool CreateArtistAccount(CreateArtist creates)
 {
     try
     {
         query1 = "Select count(*) from user_details where username=@username";
         query  = "Select count(*) from artist_details where artist_username=@username";
         cmd    = new SqlCommand(query, con);
         cmd.Parameters.AddWithValue("@username", creates.artist_username);
         cmd1 = new SqlCommand(query1, con);
         cmd1.Parameters.AddWithValue("@username", creates.artist_username);
         con.Open();
         int record  = (int)cmd.ExecuteScalar();
         int record1 = (int)cmd1.ExecuteScalar();
         if (record == 0 && record1 == 0)
         {
             cmd.Parameters.Clear();
             query = "Insert into artist_details values(@username,@names,@passwords)";
             cmd   = new SqlCommand(query, con);
             cmd.Parameters.AddWithValue("@username", creates.artist_username);
             cmd.Parameters.AddWithValue("@names", creates.name);
             cmd.Parameters.AddWithValue("@passwords", creates.password);
             cmd.ExecuteNonQuery();
             con.Close();
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
     finally
     {
         con.Close();
     }
 }
Example #7
0
 public async Task <IActionResult> Post([FromBody] CreateArtist command)
 {
     return(command == null?
            UnprocessableEntity()
                : Ok(await _mediator.Send(command)));
 }