// GET: Electrick_Lockomotive_Info/Details/5 public async Task <IActionResult> Details(int?idloc) { if (idloc == null) { return(NotFound()); } Electic_locomotive electic_Locomotives = await _context.Electic_Locomotives.Where(x => x.id == idloc).FirstOrDefaultAsync(); var electrick_Lockomotive_Info = _context.Electrick_Lockomotive_Infos.Where(m => m.Name == electic_Locomotives.Seria).FirstOrDefault(); if (electrick_Lockomotive_Info == null) { Electrick_Lockomotive_Info electrick_Lockomotive_Info_add = new Electrick_Lockomotive_Info { Name = electic_Locomotives.Seria, Power = electic_Locomotives.ALlPowerP, Diesel = electic_Locomotives.DieselPower, Electric_Type = "", Baseinfo = "", AllInfo = "" }; _context.Add(electrick_Lockomotive_Info_add); await _context.SaveChangesAsync(); } var base_info = _context.locomotiveBaseInfos.Where(x => x.Name == electic_Locomotives.Seria).Select(x => x.BaseInfo).ToList().FirstOrDefault(); ViewBag.base_info = base_info; return(View(electrick_Lockomotive_Info)); }
public async Task <IActionResult> AddImage(int?id, IFormFile uploads) { if (id != null) { if (uploads != null) { Electic_locomotive locomotive = await _context.Electic_Locomotives.Where(x => x.id == id).FirstOrDefaultAsync(); byte[] p1 = null; using (var fs1 = uploads.OpenReadStream()) using (var ms1 = new MemoryStream()) { fs1.CopyTo(ms1); p1 = ms1.ToArray(); } Trace.WriteLine(uploads.ContentType.ToString()); Trace.WriteLine(p1); locomotive.ImageMimeTypeOfData = uploads.ContentType; locomotive.Image = p1; _context.Electic_Locomotives.Update(locomotive); _context.SaveChanges(); return(RedirectToAction(nameof(Index))); } } return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> CopySubmit(int id, [Bind("id,Name,Seria, Number,Depot, Speed,SectionCount,ALlPowerP, LocomotiveImg, DieselPower, User")] Electic_locomotive electic_locomotive) { var remoteIpAddres = Request.HttpContext.Connection.RemoteIpAddress.ToString(); Users user = _context.User.Where(x => x.IpAddress.Contains(remoteIpAddres)).FirstOrDefault(); string myuser = ""; int userId = 0; if (user != null && user.Status == "true") { myuser = user.Name; userId = user.Id; } Trace.WriteLine("POST: " + this + electic_locomotive); electic_locomotive.User = myuser; electic_locomotive.UserId = userId; _context.Add(electic_locomotive); await _context.SaveChangesAsync(); SendMessage(user); int locid = _context.Electic_Locomotives.Where(x => x.Seria == electic_locomotive.Seria && x.Number == electic_locomotive.Number).Select(x => x.id).FirstOrDefault(); TempData["LocomotiveId"] = locid; Trace.WriteLine(TempData); return(RedirectToAction(nameof(AddImageForm))); Trace.WriteLine("RESPONSE: " + electic_locomotive); return(View(electic_locomotive)); }
public async Task <IActionResult> EditLocomotive(int id, [Bind("id,Name,Number,Depot,Country,City,Status,Photo")] ListRollingStone listRollingStone) { if (id != listRollingStone.id) { return(NotFound()); } if (ModelState.IsValid) { try { Trace.WriteLine("POST " + this + listRollingStone); Electic_locomotive electic_Locomotive = _context.Electic_Locomotives.Where(x => x.Seria + " - " + x.Number == listRollingStone.Name).FirstOrDefault(); _context.Update(listRollingStone); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ListRollingStoneExists(listRollingStone.id)) { return(NotFound()); } else { throw; } } } Trace.WriteLine("RESPONSE " + this + listRollingStone); return(View("IndexAll", await _context.ListRollingStones.ToListAsync())); }
public async Task <IActionResult> Edit(int id, [Bind("id,Name,Seria, Number,Depot, Speed,SectionCount,ALlPowerP, LocomotiveImg, DieselPower, User")] Electic_locomotive electic_locomotive) { var remoteIpAddres = Request.HttpContext.Connection.RemoteIpAddress.ToString(); Users user = _context.User.Where(x => x.IpAddress.Contains(remoteIpAddres)).FirstOrDefault(); string name = ""; int userid = 0; if (user != null && user.Status == "true") { name = user.Name; userid = user.Id; } if (id != electic_locomotive.id) { return(NotFound()); } if (ModelState.IsValid) { try { Trace.WriteLine("POST: " + electic_locomotive); Electic_locomotive _Locomotive = _context.Electic_Locomotives.Where(x => x.id == electic_locomotive.id).FirstOrDefault(); _Locomotive.Seria = electic_locomotive.Seria; _Locomotive.Number = electic_locomotive.Number; _Locomotive.ALlPowerP = electic_locomotive.ALlPowerP; _Locomotive.Depot = electic_locomotive.Depot; _Locomotive.SectionCount = electic_locomotive.SectionCount; _Locomotive.Speed = electic_locomotive.Speed; _Locomotive.User = name; _Locomotive.UserId = userid; _context.Update(_Locomotive); await _context.SaveChangesAsync(); SendMessage(user); } catch (DbUpdateConcurrencyException) { if (!Electic_locomotiveExists(electic_locomotive.id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } Trace.WriteLine("RESPONSE : " + electic_locomotive); return(View(electic_locomotive)); }
private void Button_Click(object sender, RoutedEventArgs e) { Electic_locomotive electic_Locomotive = new Electic_locomotive { Seria = Name.Text, LocomotiveImg = LocomotiveImg.Text, SectionCount = Convert.ToInt32(SectionCountText.Text), ALlPowerP = Convert.ToInt32(ALlPowerText.Text) }; Post.Send("Electic_locomotive", "CreateAction", this, electic_Locomotive); this.Close(); }
public FileContentResult GetImage(int id) { Electic_locomotive locomotive = _context.Electic_Locomotives .FirstOrDefault(g => g.id == id); if (locomotive != null) { var file = File(locomotive.Image, locomotive.ImageMimeTypeOfData); return(file); } else { return(null); } }
public async Task <IActionResult> Create([Bind("id,Name,Number,Depot,Country,City,Status,Photo")] ListRollingStone listRollingStone) { listRollingStone.Country = "Украина"; Electic_locomotive electic_Locomotive = _context.Electic_Locomotives.Where(x => x.Seria + " - " + x.Number == listRollingStone.Name).FirstOrDefault(); if (listRollingStone.Image == null) { listRollingStone.Image = electic_Locomotive.Image; listRollingStone.ImageMimeTypeOfData = electic_Locomotive.ImageMimeTypeOfData; } _context.Add(listRollingStone); await _context.SaveChangesAsync(); return(View("IndexAll", await _context.ListRollingStones.ToListAsync())); }