public async Task <IActionResult> Edit(int id, [Bind("id,UserName,Email,Marshrute,Type,BaseInfo,Imgsrc")] UserTrainzPhoto userTrainzPhoto) { if (id != userTrainzPhoto.id) { return(NotFound()); } if (ModelState.IsValid) { try { userTrainzPhoto.DateTime = DateTime.Now; _context.Update(userTrainzPhoto); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserTrainzPhotoExists(userTrainzPhoto.id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(userTrainzPhoto)); }
public async Task <IActionResult> AddImage(int?id, IFormFile uploads) { if (id != null) { if (uploads != null) { UserTrainzPhoto userTrainz = await _context.UserTrainzPhotos.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); userTrainz.ImageType = uploads.ContentType; userTrainz.Image = p1; _context.UserTrainzPhotos.Update(userTrainz); _context.SaveChanges(); return(RedirectToAction(nameof(Index))); } } return(RedirectToAction(nameof(Index))); }
public FileContentResult GetImage(int id) { UserTrainzPhoto trainz = _context.UserTrainzPhotos .FirstOrDefault(g => g.id == id); if (trainz != null) { var file = File(trainz.Image, trainz.ImageType); return(file); } else { return(null); } }
public async Task <IActionResult> Create([Bind("id,UserName,Email,Marshrute,Type,BaseInfo,Imgsrc")] UserTrainzPhoto userTrainzPhoto) { string username = ""; int userid = 0; var useremail = ""; var remoteIpAddres = Request.HttpContext.Connection.RemoteIpAddress.ToString(); Users user = _context.User.Where(x => x.IpAddress.Contains(remoteIpAddres)).FirstOrDefault(); if (user != null && user.Status == "true") { ViewBag.user = user; username = user.Name; userid = user.Id; useremail = user.Email; } if (userTrainzPhoto.LocmotiveName == null) { userTrainzPhoto.LocmotiveName = ""; } string email = useremail; userTrainzPhoto.Email = email; userTrainzPhoto.DateTime = DateTime.Now; userTrainzPhoto.UserName = username; userTrainzPhoto.UserId = userid; _context.Add(userTrainzPhoto); await _context.SaveChangesAsync(); TempData["UserTrainId"] = _context.UserTrainzPhotos.ToList().Count(); try { MailMessage m = new MailMessage("*****@*****.**", userTrainzPhoto.Email); m.Body = userTrainzPhoto.UserName + "Ваша публикация опубликована"; SmtpClient smtp = new SmtpClient("smtp.ukr.net", 2525); smtp.UseDefaultCredentials = true; smtp.Credentials = new NetworkCredential("sashaberduchev24", "1GFxClluVF5q1xd1"); smtp.Send(m); } catch (Exception e) { Trace.WriteLine(e.ToString()); } return(RedirectToAction(nameof(AddImageForm))); }