protected void confirmToAddItem(object sender, EventArgs e) { newName = Request.Form["clothesName"]; newSize = Request.Form["size"]; newColor = Request.Form["color"]; string newPriceStr = Request.Form["price"]; newPrice = float.Parse(newPriceStr); DateTime now = DateTime.Now; string strBaseLocation = Server.MapPath(System.Web.HttpContext.Current.Request.ApplicationPath.ToString()); if (file1.PostedFile.ContentLength != 0) { file1.PostedFile.SaveAs(strBaseLocation + now.DayOfYear.ToString() + file1.PostedFile.ContentLength.ToString() + ".jpg"); } item newItem = DBModel.sharedDBModel().addItemByBoss(newName, newSize, newColor, newPrice); image neImage = DBModel.sharedDBModel().addImageToItem(newItem.itemId, file1.PostedFile.ContentLength.ToString() + ".jpg"); }
/** * 40.Boss增加商品的图片信息 * 参数:需要增加的商品的Id,图片的地址(或者编号) * 返回:图片实例(通过测试) */ public image addImageToItem(string currentItemId, string currentImagePath) { using (YMDBEntities db = new YMDBEntities()) { try { image newImage = new image { imagePath = currentImagePath, itemId = currentItemId, }; db.image.Add(newImage); db.SaveChanges(); return newImage; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("haha~保存不了吧,好好看看参数是不输错了."); System.Diagnostics.Debug.WriteLine(ex.StackTrace); return null; } } }