public ActionResult UploadSlider(string id) { // Checking no of files injected in Request object if (Request.Files.Count > 0) { try { // Get all files from Request object HttpFileCollectionBase files = Request.Files; for (int i = 0; i < files.Count; i++) { //string path = AppDomain.CurrentDomain.BaseDirectory + "Uploads/"; //string filename = Path.GetFileName(Request.Files[i].FileName); HttpPostedFileBase file = files[i]; string fname; // Checking for Internet Explorer if (Request.Browser.Browser.ToUpper() == "IE" || Request.Browser.Browser.ToUpper() == "INTERNETEXPLORER") { string[] testfiles = file.FileName.Split(new char[] { '\\' }); fname = Guid.NewGuid().ToString() + "_" + DateTime.Today.ToShortDateString().Replace("/", "_").ToString();; } else { fname = Guid.NewGuid().ToString() + "_" + DateTime.Today.ToShortDateString().Replace("/", "_").ToString();; } string fileName = fname + Path.GetExtension(file.FileName); // Get the complete folder path and store the file inside it. fname = Path.Combine(Server.MapPath("~/Images/"), fname + Path.GetExtension(file.FileName)); file.SaveAs(fname); using (var _Entity = new GamesEntities()) { ProductImage model = new ProductImage(); model.ProductId = Convert.ToInt32(id); model.ImagePath = fileName; model.Type = "Slider"; _Entity.Entry(model).State = EntityState.Added; _Entity.SaveChanges(); TempData["Result"] = "Game Sucessfully Updated."; } } // Returns message that successfully uploaded return(Json("Image Uploaded Successfully!")); } catch (Exception ex) { return(Json("Error occurred. Error details: " + ex.Message)); } } else { return(Json("No files selected.")); } }
public ActionResult Edit([Bind(Include = "ID,Name,Phone,Email,Address")] Supplier supplier) { if (ModelState.IsValid) { db.Entry(supplier).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(supplier)); }
public ActionResult Edit([Bind(Include = "ID,Name,Email,NationalID,Phone,Address,Title,Salary,ReportsTo")] Employee employee) { if (ModelState.IsValid) { db.Entry(employee).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ReportsTo = new SelectList(db.Employees, "ID", "Name", employee.ReportsTo); return(View(employee)); }
public ActionResult DoCheckOut(Order model) { try { if (Session["MyCart"] != null) { using (var _Entity = new GamesEntities()) { model.Date = DateTime.Now; model.Status = "Pending"; _Entity.Entry(model).State = EntityState.Added; _Entity.SaveChanges(); List <CartProduct> cart = Session["MyCart"] as List <CartProduct>; foreach (var item in cart) { OrderDetail detail = new OrderDetail(); detail.OrderId = model.OrderId; detail.Product = item.Name; detail.Type = item.Type; detail.Quantity = Convert.ToInt32(item.Quantity); detail.UnitPrice = Convert.ToDecimal(item.Price); detail.TotalPrice = Convert.ToInt32(item.Total); _Entity.Entry(detail).State = EntityState.Added; _Entity.SaveChanges(); } } } Session["op"] = "true"; } catch (Exception ex) { Session["op"] = "false"; } return(Redirect("Thanks")); }
public ActionResult Edit(Game game) { if (ModelState.IsValid) { if (game.FilePhoto != null) { string _fileName = game.ID.ToString() + Path.GetExtension(game.FilePhoto.FileName); game.Image = _fileName; _fileName = Path.Combine(Server.MapPath("~/Upload/Images/") + _fileName); game.FilePhoto.SaveAs(_fileName); } db.Entry(game).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(game)); }
public ActionResult AddExchange(Exchange model) { try { using (var _Entity = new GamesEntities()) { _Entity.Entry(model).State = (model.ExchangeId == 0 ? EntityState.Added : EntityState.Modified); _Entity.SaveChanges(); TempData["Result"] = "Game Sucessfully Updated."; return(RedirectToAction("ExchangeList")); } } catch (Exception e) { TempData["Error"] = "Error : " + e.Message.ToString(); return(RedirectToAction("ExchangeList")); } }
public ActionResult AddProduct(Product model) { string Action = "Index"; string DefaultView = "Product"; if (model.Type == "Game") { Action = "Index"; DefaultView = "Game"; } if (model.Type == "Acc") { Action = "AccList"; } if (model.Type == "Console") { Action = "Consoles"; } try { //if (!ModelState.IsValid) // return View("Game"); using (var _Entity = new GamesEntities()) { _Entity.Entry(model).State = (model.ProductId == 0 ? EntityState.Added : EntityState.Modified); _Entity.SaveChanges(); TempData["Result"] = "Game Sucessfully Updated."; return(RedirectToAction(Action)); } } catch (Exception e) { TempData["Error"] = "Error : " + e.Message.ToString(); return(View(DefaultView)); //return Json("false", JsonRequestBehavior.AllowGet); } }
public ActionResult Create(Xbox xb) { try { var data = db.Entry(xb).State = System.Data.Entity.EntityState.Added; int a = db.SaveChanges(); if (a > 0) { return(RedirectToAction("Index")); } else { return(View(data)); } } catch { return(View()); } }
public ActionResult Create(PS4 ps) { try { // TODO: Add insert logic here var data = db.Entry(ps).State = System.Data.Entity.EntityState.Added; int a = db.SaveChanges(); if (a > 0) { return(RedirectToAction("Index")); } else { return(View(data)); } } catch { return(View()); } }
public async Task TesteMetacritic() { GamesEntities db = new GamesEntities(); List <game_platform> games = db.game_platform.Where(gp => gp.metacritic == null).ToList(); foreach (game_platform g in games) { GameEntity jogo = db.game.Find(g.id_game); platform plataforma = db.platform.Find(g.id_platform); string sigla; switch (plataforma.sigla) { case "PS1": sigla = "PS"; break; case "PSVITA": sigla = "VITA"; break; default: sigla = plataforma.sigla; break; } try { var metacritic = await Metacritic.SearchFor().Games().UsingTextAsync(jogo.name); var resultado = metacritic.Where(m => m.Platform == sigla).Where(m => m.Name == jogo.name).FirstOrDefault(); if (resultado != null) { g.metacritic = resultado.Score; db.Entry(g).State = EntityState.Modified; } } catch (Exception ex) { } } db.SaveChanges(); }
public void Teste() { GamesEntities db = new GamesEntities(); IgdbService igdb = new IgdbService(); List <game_platform> games = db.game_platform.Where(gp => gp.release_date == null).Where(gp => gp.id_status == 1).ToList(); foreach (game_platform g in games) { GameEntity jogo = db.game.Find(g.id_game); try { platform plataforma = db.platform.Find(g.id_platform); DadosGameResponse dados = igdb.DadosJogo(jogo.id_igdb.Value).FirstOrDefault(); ReleaseDate lancamento; if (g.id_region == null) { lancamento = dados.ReleaseDates.Where(r => r.Region == 8).Where(r => r.Platform == plataforma.id_igdb).FirstOrDefault(); if (lancamento == null) { lancamento = dados.ReleaseDates.Where(r => r.Region == 2).Where(r => r.Platform == plataforma.id_igdb).FirstOrDefault(); } if (lancamento != null) { g.id_region = lancamento.Region; } } else { lancamento = dados.ReleaseDates.Where(r => r.Region == g.id_region).Where(r => r.Platform == plataforma.id_igdb).FirstOrDefault(); if (lancamento == null) { lancamento = dados.ReleaseDates.Where(r => r.Region == 8).Where(r => r.Platform == plataforma.id_igdb).FirstOrDefault(); } if (lancamento == null) { lancamento = dados.ReleaseDates.Where(r => r.Region == 2).Where(r => r.Platform == plataforma.id_igdb).FirstOrDefault(); } if (lancamento == null) { if (plataforma.id != 7) { lancamento = dados.ReleaseDates.Where(r => r.Region == 8).Where(r => r.Platform == 45).FirstOrDefault(); if (lancamento == null) { lancamento = dados.ReleaseDates.Where(r => r.Region == 2).Where(r => r.Platform == 45).FirstOrDefault(); } } } } if (lancamento != null) { if (lancamento.Date != null) { DateTime data = new DateTime(1970, 1, 1, 0, 0, 0).AddMilliseconds(Convert.ToDouble(Convert.ToDouble(lancamento.Date))); g.release_date = data; db.Entry(g).State = EntityState.Modified; } } } catch (Exception ex) { Console.Write(jogo.name + " " + ex.Message); } } db.SaveChanges(); }