public HttpResponseMessage Put(int id, PosterUpdateRequest model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             PosterService   svc      = new PosterService();
             SuccessResponse response = new SuccessResponse();
             svc.Update(model);
             return(Request.CreateResponse(HttpStatusCode.OK, response));
         }
         else
         {
             return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message));
     }
 }
Exemple #2
0
        public void Update(PosterUpdateRequest model)
        {
            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                string cmdText = "Poster_Update";
                using (SqlCommand cmd = new SqlCommand(cmdText, conn))
                {
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@Id", model.Id);
                    cmd.Parameters.AddWithValue("@Title", model.Title);
                    cmd.Parameters.AddWithValue("@Description", model.Description);
                    cmd.Parameters.AddWithValue("@Type", model.Type);
                    cmd.Parameters.AddWithValue("@Price", model.Price);
                    cmd.Parameters.AddWithValue("@ImageUrl", model.ImageUrl);
                    cmd.Parameters.AddWithValue("@ModifiedBy", model.ModifiedBy);

                    conn.Open();
                    cmd.ExecuteNonQuery();

                    conn.Close();
                }
            }
        }