public ActionResult Post(Post post, ImageFile objImage) { int UserID = Convert.ToInt32(Session["UserId"].ToString()); client.Post1(post.title, post.content, UserID); var currentPosted = client.CurrentPost(post.title); foreach (var file in objImage.files) { if (file != null && file.ContentLength > 0) { // User user = (User)Session["User"]; string fileName = Path.GetFileNameWithoutExtension(file.FileName); string extension = Path.GetExtension(file.FileName); fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension; string filePath = "~/Uploads/" + fileName; string DatePosted = DateTime.Now.ToString("yymmssfff"); // Random rnd = new Random(); // int fileId = rnd.Next(1, 100); var image = new ServiceReference1.ImagePost() { Name = fileName, Path = filePath }; client.ImagePost(image, currentPosted.id); file.SaveAs(Path.Combine(Server.MapPath("/Uploads"), fileName)); } } return(RedirectToAction("Search")); }
public ActionResult Registor(Travel traveler, ImageFile objImage) { try { // TODO: Add insert logic here var travel = new ServiceReference1.Traveler() { address = traveler.address, dob = traveler.DOB, email = traveler.email, firstName = traveler.firstname, lastName = traveler.lastName, password = traveler.password, phone = traveler.phone, RoleId = traveler.RoleId }; client.Registor(travel); var UserRegistor = client.GetTrallerByEmail(traveler.email); foreach (var file in objImage.files) { if (file != null && file.ContentLength > 0) { // User user = (User)Session["User"]; string fileName = Path.GetFileNameWithoutExtension(file.FileName); string extension = Path.GetExtension(file.FileName); fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension; string filePath = "~/Uploads/" + fileName; string DatePosted = DateTime.Now.ToString("yymmssfff"); // Random rnd = new Random(); // int fileId = rnd.Next(1, 100); var image = new ServiceReference1.ImagePost() { Name = fileName, Path = filePath }; client.ImageUserPost(image, UserRegistor.id); file.SaveAs(Path.Combine(Server.MapPath("/Uploads"), fileName)); } } return(RedirectToAction("Search")); } catch { return(View()); } }