public int UploadPicture(HttpPostedFileBase file) { if (file != null) { if (file.ContentLength > 800 * 1024) { return(400); } if (file.ContentLength > 0) { Guid name = Guid.NewGuid(); var fileName = name + "." + Path.GetFileName(file.ContentType); var path = Path.Combine(Server.MapPath("~/img/" + SchoolName), fileName); file.SaveAs(path); PictureModels Picture = new PictureModels(); Picture.Filename = Path.GetFileName(file.FileName); Picture.Name = name; Picture.FullName = string.Format("/img/{0}/", SchoolName) + fileName; Picture.School = SchoolID; Picture.CreatedTime = DateTime.Now; db.Picture.Add(Picture); db.SaveChanges(); return(200); } } return(500); }
public async Task <IHttpActionResult> GetPicture(string searchKey) { PictureModels models = await this.mPictureService.GetPictures(PicturePrefix + searchKey); return(this.Json(models)); }