예제 #1
0
        public async Task <JsonResult> UploadPhoto(string Userid)
        {
            JsonResult jResult = new JsonResult();
            var        file    = HttpContext.Current.Request.Files.Count > 0 ?
                                 HttpContext.Current.Request.Files[0] :  null;

            if (file == null)
            {
                jResult.Data = new { Success = false, Message = "Photo is empty or null" };

                return(jResult);
            }
            string fileName   = Path.GetFileNameWithoutExtension(file.FileName);
            string extesntion = Path.GetExtension(file.FileName);

            fileName = fileName + DateTime.Now.ToString("yymmssfff") + extesntion;
            string pathApi = Path.Combine(System.Web.HttpContext.Current.Server.MapPath("~/Content/images/"), fileName);

            if (file.FileName.Length > 0)
            {
                file.SaveAs(pathApi);
            }

            Picture picture = new Picture()
            {
                URL        = "api.jomlahjo.com/Content/images/" + fileName,
                ModifiedOn = DateTime.Now
            };

            return(await userApiService.AddUserPictuer(Userid, picture));
        }