public void Post() { var httpRequest = HttpContext.Current.Request; foreach (string file in httpRequest.Files) { var postedFile = httpRequest.Files[file]; byte[] bytes; using (BinaryReader br = new BinaryReader(postedFile.InputStream)) { bytes = br.ReadBytes(postedFile.ContentLength); } var name = httpRequest.Form["name"]; var price = httpRequest.Form["price"]; var pr = Convert.ToInt32(price); ImageEntity image = new ImageEntity() { Name = postedFile.FileName, ContentType = postedFile.ContentType, Data = bytes }; HairItem hair = new HairItem() { Name = name, Price = Convert.ToInt32(price), HairImage = image }; context.Images.Add(image); context.HairItems.Add(hair); context.SaveChanges(); } }
// this is used for OGS1 public virtual Hashtable ToHashTable() { Hashtable h = new Hashtable(); h["owner"] = Owner.ToString(); h["serial"] = Serial.ToString(); h["visual_params"] = VisualParams; h["texture"] = Texture.GetBytes(); h["avatar_height"] = AvatarHeight.ToString(); h["body_item"] = BodyItem.ToString(); h["body_asset"] = BodyAsset.ToString(); h["skin_item"] = SkinItem.ToString(); h["skin_asset"] = SkinAsset.ToString(); h["hair_item"] = HairItem.ToString(); h["hair_asset"] = HairAsset.ToString(); h["eyes_item"] = EyesItem.ToString(); h["eyes_asset"] = EyesAsset.ToString(); h["shirt_item"] = ShirtItem.ToString(); h["shirt_asset"] = ShirtAsset.ToString(); h["pants_item"] = PantsItem.ToString(); h["pants_asset"] = PantsAsset.ToString(); h["shoes_item"] = ShoesItem.ToString(); h["shoes_asset"] = ShoesAsset.ToString(); h["socks_item"] = SocksItem.ToString(); h["socks_asset"] = SocksAsset.ToString(); h["jacket_item"] = JacketItem.ToString(); h["jacket_asset"] = JacketAsset.ToString(); h["gloves_item"] = GlovesItem.ToString(); h["gloves_asset"] = GlovesAsset.ToString(); h["undershirt_item"] = UnderShirtItem.ToString(); h["undershirt_asset"] = UnderShirtAsset.ToString(); h["underpants_item"] = UnderPantsItem.ToString(); h["underpants_asset"] = UnderPantsAsset.ToString(); h["skirt_item"] = SkirtItem.ToString(); h["skirt_asset"] = SkirtAsset.ToString(); string attachments = GetAttachmentsString(); if (attachments != String.Empty) { h["attachments"] = attachments; } return(h); }
public JsonResult AddHair([System.Web.Http.FromBody] HairViewModel model) { using (AppContext context = AppContext.Create()) { if (!ModelState.IsValid) { return(Json(false)); } //byte[] bytes; //using (BinaryReader br = new BinaryReader(model.PostedImage.InputStream)) //{ // bytes = br.ReadBytes(model.PostedImage.ContentLength); //} //ImageEntity image = new ImageEntity() { Name = model.PostedImage.FileName, ContentType = model.PostedImage.ContentType, Data = bytes }; HairItem hairItem = new HairItem() { Name = model.Name, Price = model.Price, HairImage = model.PostedImageData, HairType = model.HairType }; foreach (HairLength length in model.HairLengths) { hairItem.HairLengths.Add(length); } foreach (HairColor color in model.HairColors) { hairItem.HairColors.Add(color); } //context.Images.Add(image); context.HairItems.Add(hairItem); context.SaveChanges(); return(Json(true)); } }