public JsonResult UploadPicture(string id) { try { user us = Session["user"] as user; string path = Server.MapPath("~/Content/Upload/"); HttpFileCollectionBase files = Request.Files; for (int i = 0; i < files.Count; i++) { string fileName = Helper.GetHashAndRandom32.Random32(); HttpPostedFileBase file = files[i]; using (Image image = Image.FromStream(file.InputStream)) { image.Save(path + fileName + ".png", ImageFormat.Png); } _db.Sliders.Add(new Slider { Name = fileName, CreateDate = DateTime.Now, IsActive = false, UserID = us.ID, Description = id }); _db.SaveChanges(); } return(Json(true)); } catch { return(Json(false)); } }
public JsonResult AddPetPicture() { user us = Session["user"] as user; string path = Server.MapPath("~/Content/Market/"); HttpFileCollectionBase files = Request.Files; string fileName = ""; for (int i = 0; i < files.Count; i++) { fileName = Helper.GetHashAndRandom32.Random32(); HttpPostedFileBase file = files[i]; using (Image image = Image.FromStream(file.InputStream)) { image.Save(path + fileName + ".png", ImageFormat.Png); } _db.Markets.Add(new Market { Picture = fileName, UserID = us.ID, Description = "11", Age = 11, Breed = "11", ContactPerson = "11", Currency = "11", Gender = "11", Location = "11", PhoneNumber = "11", Price = 11, Title = "11", Type = "11", }); _db.SaveChanges(); } return(Json(_db.Markets.FirstOrDefault(x => x.Picture == fileName)?.ID)); }
public ActionResult Registration(Register userModel) { if (ModelState.IsValid) { using (var db = new PetPawEntities()) { TimeSpan t = DateTime.Now - userModel.Birthdate; DateTime zeroTime = new DateTime(1, 1, 1); int years = (zeroTime + t).Year - 1; if (db.users.Any(x => x.Email == userModel.Email)) { return Content("მითითებული მეილით უკვე დარეგისტრირებულია მომხმარებელი"); } user user = new user { Email = userModel.Email, firstName = userModel.FirstName, lastName = userModel.LastName, Password = Helper.GetHashAndRandom32.MD5Hash(userModel.Password), Date = DateTime.Now, resetPassword = Helper.GetHashAndRandom32.Random32(), Sex = userModel.Gender == 1 ? "male" : "keso", Age = years, profilePicture = Helper.GetHashAndRandom32.Random32(), phoneNumber = userModel.phoneNumber, Role = 50 }; db.users.Add(user); db.SaveChanges(); return RedirectToAction("Login", "Account"); } } else { return View(userModel); } }