示例#1
0
        public async Task <IHttpActionResult> AddNewPhoto(Photo ph)
        {
            var pathName = "PenjualanPhotoGalery";

            ph.Path = pathName;
            var path = HttpContext.Current.Server.MapPath(string.Format("~/{0}/", pathName));

            //if (!Request.Content.IsMimeMultipartContent())
            //    throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotAcceptable,
            //    "This request is not properly formatted"));
            //var streamProvider = new MultipartFileStreamProvider(path);
            //var res= await Request.Content.ReadAsMultipartAsync(streamProvider);
            try
            {
                if (ph != null)
                {
                    var context = new PhotoContext(path);
                    return(Ok(await context.AddNewPhoto(ph, pathName)));
                }
                else
                {
                    throw new SystemException("Tidak ada gambar yang dikirim");
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
示例#2
0
 public async Task <IActionResult> Post(Photo ph)
 {
     ph.Path = $"wwwroot/bukti/pictures/";
     try
     {
         if (ph != null)
         {
             return(Ok(await context.AddNewPhoto(ph)));
         }
         else
         {
             throw new SystemException("Tidak ada gambar yang dikirim");
         }
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }