Example #1
0
        public IHttpActionResult PutActor(int id)
        {
            HttpRequestMessage request = this.Request;

            if (!request.Content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }

            string root = System.Web.HttpContext.Current.Server.MapPath("~/Content/images/actors");

            // Get the uploaded image from the Files collection
            var httpPostedFile = HttpContext.Current.Request.Files["image"];
            var actor          = JsonConvert.DeserializeObject <Actor>(HttpContext.Current.Request.Form[0]);

            Validate(actor);
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (httpPostedFile != null)
            {
                // Validate the uploaded image(optional)
                var extension = new FileInfo(httpPostedFile.FileName).Extension;
                var fileName  = Guid.NewGuid() + extension;
                // Get the complete file path
                var fileSavePath = Path.Combine(root, fileName);

                while (File.Exists(fileSavePath))
                {
                    fileName     = Guid.NewGuid() + extension;
                    fileSavePath = Path.Combine(root, fileName);
                }
                // Save the uploaded file to "UploadedFiles" folder
                httpPostedFile.SaveAs(fileSavePath);
                actor.Image = "http://localhost:50000/Content/images/actors/" + fileName;
            }


            if (id != actor.Id)
            {
                return(BadRequest());
            }

            _dALActor.UpdateActor(actor);

            return(StatusCode(HttpStatusCode.NoContent));
        }
 private void UpdateActorExecute()
 {
     if (!string.IsNullOrEmpty(Actor.Name) && !string.IsNullOrEmpty(Actor.Surname))
     {
         _dALHelper.UpdateActor(_actor);
         zanrWindow.Close();
     }
 }