public async Task <ActionResult> Create( [Bind(Include = "Id,Name,Log,Contact,Describe,Theme,CreateTime,UpdateTime,CreateBy,UpdateBy,TenantId")] Shop_Info shop_Info) { if (ModelState.IsValid) { shop_Info.Id = Guid.NewGuid(); SetModelWithChangeStates(shop_Info, default(Guid?)); //创建店铺相册 var photoGallery = new Site_PhotoGallery(); photoGallery.Id = shop_Info.Id; photoGallery.Title = "【" + shop_Info.Name + "】-店铺相册"; SetModelWithChangeStates(photoGallery, default(Guid?)); db.Site_PhotoGallerys.Add(photoGallery); //上传店铺LOGO var file = Request.Files[0]; if (file != null) { var photoDO = new PhotoDO(); var logoGuid = photoDO.Add(shop_Info.Id, "【" + shop_Info.Name + "】-店铺LOGO" + Path.GetExtension(file.FileName), file.InputStream); shop_Info.Logo = logoGuid; } db.Shop_Infos.Add(shop_Info); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(shop_Info)); }
public ActionResult Upload(Guid Id, string message = null) { var ajaxMessage = new AjaxResponse { Success = true, Message = "上传成功!" }; if (Id == null) { ajaxMessage.Success = false; ajaxMessage.Message = "产品不存在或已删除!"; return(Json(ajaxMessage)); } foreach (var fileKey in Request.Files.AllKeys) { var file = Request.Files[fileKey]; try { if (file != null) { var photoDO = new PhotoDO(); photoDO.Add(Id, "商品相册" + Path.GetExtension(file.FileName), file.InputStream); } } catch (Exception ex) { ajaxMessage.Success = false; ajaxMessage.Message = ex.Message; } } return(Json(ajaxMessage)); }
public async Task <ActionResult> Edit( [Bind(Include = "Id,Name,Log,Contact,Describe,Theme,CreateTime,UpdateTime,CreateBy,UpdateBy,TenantId")] Shop_Info shop_Info) { if (ModelState.IsValid) { SetModelWithChangeStates(shop_Info, shop_Info.Id); //上传店铺LOGO var file = Request.Files[0]; if (file != null) { var photo = db.Site_Photos.FirstOrDefault(p => p.GalleryId == shop_Info.Id); db.Site_Photos.Remove(photo); var photoDO = new PhotoDO(); var logoGuid = photoDO.Add(shop_Info.Id, "【" + shop_Info.Name + "】-店铺LOGO" + Path.GetExtension(file.FileName), file.InputStream); shop_Info.Logo = logoGuid; } await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(shop_Info)); }