private ComingSoonGameViewModel CreateComingSoonGameVM(Game iGame) { AccountService service = new AccountService(db, null); ComingSoonGameViewModel ComingSoonGameVM = new ComingSoonGameViewModel(iGame.GameID); if (Request.IsAuthenticated) { ComingSoonGameVM.LoggedInMemberID = service.findMember(User.Identity.Name).MemberID; } ComingSoonGameVM.Game = iGame; ComingSoonGameVM.ProductInGame = iGame.ProductInGames.First(); var product = db.Products.Include(x => x.Imagedetails).Where(x => x.ProductID == ComingSoonGameVM.ProductInGame.ProductID).First(); if (product.Imagedetails.Count() == 0) { Imagedetail empty = new Imagedetail(); empty.ImageName = "Main Image"; empty.ImageID = 1; ///TODO 1 is empty image product.Imagedetails.Add(empty); } // ComingSoonGameVM.mainImage = product.Images.Where(c => c..ToLower() == "main image").Count() > 0 ? // ComingSoonGameVM.mainImage = product.Images.Where(c => c..ToLower() == "main image").First() : //TODO fix main image thing ComingSoonGameVM.mainImage = product.Imagedetails.First(); return(ComingSoonGameVM); }
private void saveFile(HttpPostedFileBase file, int productId) { Dictionary <Enums.ImageType, string> versions = new Dictionary <Enums.ImageType, string>(); //Define the versions to generate versions.Add(Enums.ImageType.thumb, "width=75&height=75&crop=auto&format=jpg"); //Crop to square thumbnail versions.Add(Enums.ImageType.medium, "maxwidth=200&maxheight=200&format=jpg"); //Fit inside 400x400 area, jpeg versions.Add(Enums.ImageType.large, "maxwidth=540&maxheight=450&format=jpg"); //Fit inside 1900x1200 area foreach (string fileKey in System.Web.HttpContext.Current.Request.Files.Keys) { // HttpPostedFile file = HttpContext.Current.Request.Files[fileKey]; if (file.ContentLength <= 0) { continue; //Skip unused file controls. } //To store the list of generated paths List <MemoryStream> generatedFiles = new List <MemoryStream>(); //Generate each version foreach (Enums.ImageType suffix in versions.Keys) //Let the image builder add the correct extension based on the output file type { Imagedetail newImage = new Imagedetail(); newImage.ImageName = file.FileName; //Here's where the ContentType column comes in handy. By saving // this to the database, it makes it infinitely easier to get it back // later when trying to show the image. newImage.ContentType = file.ContentType; if (suffix.Equals(Enums.ImageType.thumb)) { newImage.ImageTypeID = 1; } else if (suffix.Equals(Enums.ImageType.medium)) { newImage.ImageTypeID = 2; } else { newImage.ImageTypeID = 3; } var resultStream = new MemoryStream(); newImage.ImageName = suffix + newImage.ImageName; ImageBuilder.Current.Build(file, resultStream, new ResizeSettings(versions[suffix]), false, true); MemoryStream imageInmemory = new MemoryStream(); Int64 length = resultStream.Length; byte[] binaryData = resultStream.ToArray(); //string temp = Convert.ToBase64String(binaryData); newImage.ImageContent = binaryData; db.Imagedetails.Add(newImage); } } db.SaveChanges(); return; }
//public ActionResult Edit([Bind(Include = "ProductID,ProductSKUCode,OwnerID,ContractID,ProductName,ProductDescription,DateInserted,DateUpdated,USR")] Product product) public ActionResult Edit(ProductViewModel productViewModel) { var product = productViewModel.Product; product = (Product)Helpers.TableTracker.TrackEdit(product, "USR"); ProductValidator validator = new ProductValidator(); if (ModelState.IsValid && validator.Validate(product).IsValid) { if (productViewModel.Images != null) { foreach (var d in productViewModel.Images) { if (d.DeleteOnSave) { Imagedetail image = db.Imagedetails.Where(x => x.ImageID == d.Image.ImageID).First(); db.Imagedetails.Remove(image); } } } db.Entry(productViewModel.Product).State = EntityState.Modified; db.SaveChanges(); int count = 0; foreach (string fileName in Request.Files) { HttpPostedFileBase file = Request.Files[count++]; saveFile(file, productViewModel.Product.ProductID); } return(RedirectToAction("Index")); } ValidationResult results = validator.Validate(product); IList <ValidationFailure> failures = results.Errors; StringBuilder sb = new StringBuilder(); foreach (var e in results.Errors) { ModelState.AddModelError(e.PropertyName + "Error", e.ErrorMessage); sb.AppendLine(e.ErrorMessage); } //ViewBag.ValidationErrors = sb.ToString(); ViewBag.ContractIDList = new SelectList(db.Contracts, "ContractID", "ContractCode", productViewModel.Product.ContractID); ViewBag.OwnerIDList = new SelectList(db.Owners, "OwnerID", "OwnerCode", productViewModel.Product.OwnerID); return(View(productViewModel)); }
public ActionResult Index(int imageId) { VaultLifeApplicationEntities db = new VaultLifeApplicationEntities(); //This is my method for getting the image information // including the image byte array from the image column in // a database. Imagedetail image = db.Imagedetails.Where(x => x.ImageID == imageId).First(); //As you can see the use is stupid simple. Just get the image bytes and the // saved content type. See this is where the contentType comes in real handy. ImageResult result = new ImageResult(image.ImageContent, image.ContentType); return(result); }
public static void SaveImage(string last_id = "") { string repsonsestr = HttpHelper.SendGet("http://mobile.shenmeiguan.cn/folder/cherrypick/"); if (last_id != "") { repsonsestr = HttpHelper.SendGet("http://mobile.shenmeiguan.cn/folder/cherrypick/?last_id=" + last_id); } Rootobject rb = JsonConvert.DeserializeObject <Rootobject>(repsonsestr); if (rb != null && rb.rt == true) { //遍历集合创建文件夹 foreach (List lis in rb.list) { string dertory = string.Format(@"C:\PickEmoticon\{0}", lis.folder.name); if (!System.IO.Directory.Exists(dertory)) { try { System.IO.Directory.CreateDirectory(dertory); } catch (Exception) { dertory = string.Format(@"C:\PickEmoticon\{0}", DateTime.Now.ToString("yyyyMMddhh24mmss")); } } string detailurl = "http://mobile.shenmeiguan.cn/user/social/" + lis.user.id + "/" + "folder/" + lis.folder.id + "?pagesize=200"; repsonsestr = HttpHelper.SendGet(detailurl); Imagedetail imgdetail = JsonConvert.DeserializeObject <Imagedetail>(repsonsestr); if (imgdetail != null && imgdetail.rt == true) { foreach (Emotion em in imgdetail.emotions.ToList()) { //根据路径创建图片 getimages(dertory, em.url, em.online_id.ToString()); } } } SaveImage(rb.last_id.ToString()); } }
public static void SaveDetailImage(string usrid, string folderid, string dertory, string last_id = "") { string detailurl = ""; if (last_id != "") { detailurl = "http://mobile.shenmeiguan.cn/user/social/" + usrid + "/" + "folder/" + folderid + "?pagesize=30&last_id=" + last_id; } else { detailurl = "http://mobile.shenmeiguan.cn/user/social/" + usrid + "/" + "folder/" + folderid + "?pagesize=30"; } string repsonsestr = HttpHelper.SendGet(detailurl); Imagedetail imgdetail = JsonConvert.DeserializeObject <Imagedetail>(repsonsestr); if (imgdetail != null && imgdetail.rt == true) { foreach (Emotion em in imgdetail.emotions.ToList()) { //根据路径创建图片 getimages(dertory, em.url, em.online_id.ToString()); } } }
public string GetItemsInGamesByMember(FormDataCollection formData) { if (formData != null) { string memberIDString = formData.Get("MemberID"); string returnLimitString = formData.Get("ReturnLimit"); int MemberID = Convert.ToInt32(memberIDString); int ReturnLimit = Convert.ToInt32(returnLimitString); if (MemberID > 0 && ReturnLimit > 0) { IQueryable <MemberInGame> memberInGames = db.MemberInGames.Include("Game.ProductInGames.Product.Imagedetails").Include("Game.GameType").Include("Game.GameRules").Where(x => x.MemberID == MemberID).Take(ReturnLimit); List <MemberInGameItem> memberInGameItems = new List <MemberInGameItem>(); foreach (MemberInGame memberInGame in memberInGames) { MemberInGameItem memberInGameItem = new MemberInGameItem(); // This should happen in the constructor of MemberInGameItem. memberInGameItem.GameDateTime = DateTime.MinValue; memberInGameItem.DateTimeInserted = DateTime.MinValue; memberInGameItem.DateTimeUpdated = DateTime.MinValue; Game game = memberInGame.Game; // Set Game properties memberInGameItem.GameID = game.GameID; memberInGameItem.GameCode = game.GameCode; memberInGameItem.GameDescription = game.GameDescription; memberInGameItem.GameName = game.GameName; memberInGameItem.GameTypeName = game.GameType.GameTypeName; //memberInGameItem.GameDateTime = ; comes from game rules where state = ? //memberInGameItem.GamePrice = ; //memberInGameItem.GameStatus = ; //memberInGameItem.GameStatusColor = ; // set product properties - this needs to be a collection in the MemberInGameItem class, it's not a 1:1 relationship, 1 game can have * products. // I'm only taking the first one at this point. foreach (ProductInGame productInGame in game.ProductInGames) { Product product = productInGame.Product; memberInGameItem.ProductID = product.ProductID; memberInGameItem.ProductName = product.ProductName; memberInGameItem.ProductDescription = product.ProductDescription; memberInGameItem.ProductPrice = (product.ProductPrice != null) ? (decimal)product.ProductPrice : 0; memberInGameItem.OwnerID = product.OwnerID; // loop through product categories.... because one product can live in multiple categories!!! // I'm only taking the first one at this point. foreach (ProductInCategory productInCategory in product.ProductInCategories) { ProductCategory productCategory = productInCategory.ProductCategory; memberInGameItem.ProductCategory = productCategory.ProductCategoryName; break; } //Quick hack to get the 1st image Imagedetail image = db.Imagedetails.Where(x => x.ProductId == product.ProductID).First(); memberInGameItem.ProductImage = image.ImageID.ToString(); break; } memberInGameItems.Add(memberInGameItem); } // string returnJSONResult = ""; /*using (MemoryStream memoryStream = new MemoryStream()) * { * DataContractJsonSerializer dataContractJsonSerializer = new DataContractJsonSerializer(typeof(MemberInGameItem)); * dataContractJsonSerializer.WriteObject(memoryStream, memberInGameItems); * * memoryStream.Position = 0; * var sr = new StreamReader(memoryStream); * returnJSONResult = sr.ReadToEnd(); * } * return returnJSONResult; */ System.Web.Mvc.JsonResult json = new System.Web.Mvc.JsonResult { Data = memberInGameItems }; string son = new JavaScriptSerializer().Serialize(json.Data); return(son); } } return(""); }