public ActionResult Create(Thingy thingy) { thingy.Images = ImagesToAdd; _collection.InsertOne(thingy); ImagesToAdd.Clear(); return(RedirectToAction("index", "manage")); }
public ActionResult Update(string id, Thingy newThingy) { try { var objId = new ObjectId(id); if (ImagesToAdd.Count > 0) { var oldThing = _collection.Find(x => x.Id == objId).First(); newThingy.Images = oldThing.Images; newThingy.Images.AddRange(ImagesToAdd); } else { var oldThing = _collection.Find(x => x.Id == objId).First(); newThingy.Images = oldThing.Images; } foreach (var imageId in ImagesToRemove) { newThingy.Images.RemoveAt(imageId); } newThingy.Id = objId; _collection.ReplaceOne(x => x.Id == newThingy.Id, newThingy); } finally { ImagesToRemove.Clear(); ImagesToAdd.Clear(); } return(RedirectToAction("index", "manage")); }
public ActionResult Instagram() { string id = "sorokin_sad"; List <Thingy> things = new List <Thingy>(); using (WebClient wc = new WebClient()) { try { string json = wc.DownloadString("https://www.instagram.com/" + id + "/media/"); JObject obj = (JObject)JsonConvert.DeserializeObject(json); int i = 1; foreach (var value in obj.First.Values()) { var imageObject = value.Value <JObject>("images").Value <JObject>("standart_resolution"); if (imageObject == null) { imageObject = value.Value <JObject>("images").Value <JObject>("low_resolution"); } string imageUrl = imageObject.Value <string>("url"); var caption = value.Value <JObject>("caption"); string description = caption == null ? "" : caption.GetValue("text").ToString(); var array = ImageHelper.GetImage(imageUrl); Thingy thing = new Thingy() { Images = new List <byte[]> { array, array, array }, Name = "Из инсты #" + i, Description = description, Price = new Random().Next(1, 15) * 100 }; things.Add(thing); //images.Add(imageUrl); i++; } } catch (Exception e) { return(RedirectToAction("index", "manage")); } } _collection.DeleteManyAsync(i => true); _collection.InsertMany(things); // return View("insta",images); return(RedirectToAction("index", "manage")); }
internal void Add(Thingy thing) { var same = Items.FirstOrDefault(i => i.Thing.Id == thing.Id); if (same != null) { same.Count++; } else { Items.Add(new CartItem(thing)); } // Items.Sort(); }
public CartItem(Thingy thing) { Thing = thing; }