public UserController(IUsersRepository usersRepository, ImageUploader imageUploader, IOrdersRepository ordersRepository, IProductsRepository productsRepository) { _usersRepository = usersRepository; _imageUploader = imageUploader; _ordersRepository = ordersRepository; _productsRepository = productsRepository; }
protected void UploadButton_Click(object sender, EventArgs e) { try { #if DEBUG System.Threading.Thread.Sleep(3 * 1000); #endif UploadPanel.Visible = false; ShowPanel.Visible = true; filename = Server.MapPath("~/App_Data/imgUpload/") + Guid.NewGuid() + Path.GetExtension(ImageUploader.FileName); ImageUploader.SaveAs(filename); ImageUploader.Dispose(); Global.PhotoHandler.Detect(filename, PHandler_OnFinished); } catch (Exception ex) { Logger.WriteLog(nameof(UploadButton_Click), ex); } }
public ActionResult AddProduct([Bind(Prefix = "Product")] Product item, HttpPostedFileBase resim) { item.ImagePath = ImageUploader.UploadImage("~/Pictures/", resim); pRep.Add(item); return(RedirectToAction("ProductList")); }
public JsonResult UploadAvatar(string id) { var file = Request.Files.Get("myfile"); var uploader = new ImageUploader(file); uploader.Quality = CompositingQuality.HighQuality; uploader.Interpolation = InterpolationMode.HighQualityBilinear; int userId = (User.IsInRole("Administrator")) ? Convert.ToInt32(id) : WebSecurity.CurrentUserId; try { uploader.Convert(ProjectConfiguration.Get.UserAvatarWidth, ProjectConfiguration.Get.UserAvatarHeight); _profileRepository.UpdateAvatar(userId, uploader.UniqueName); uploader.Save("avatars"); } catch (Exception) { return(Json(new { status = "fail" }, "text/html")); } var result = new { newFilename = uploader.UniqueName, status = "success" }; return(Json(result, "text/html")); }
public ActionResult Update(PostDTO data, HttpPostedFileBase Image) { List <string> UploadImagePaths = new List <string>(); UploadImagePaths = ImageUploader.UploadSingleImage(ImageUploader.OriginalProfileImagePath, Image, 1); data.ImagePath = UploadImagePaths[0]; Post post = _postRepo.GetById(data.Id); if (data.ImagePath == "1" || data.ImagePath == "2" || data.ImagePath == "3") { if (post.ImagePath == null || post.ImagePath == ImageUploader.DefaultProfileImagePath) { post.ImagePath = ImageUploader.DefaultProfileImagePath; post.ImagePath = ImageUploader.DefaultXSmallProfileImagePath; post.ImagePath = ImageUploader.DefaultCruptedProfileImagePath; } } else { post.ImagePath = UploadImagePaths[0]; post.ImagePath = UploadImagePaths[1]; post.ImagePath = UploadImagePaths[2]; } post.Header = data.Header; post.Content = data.Content; post.CategoryId = data.CategoryId; post.AppUserId = data.AppUserId; post.status = Status.Active; post.ModifiedDate = DateTime.Now; _postRepo.Update(post); return(Redirect("/Admin/Post/List")); }
// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { IngredientTypes = new SelectList(_context.Set <IngredientType>(), nameof(Ingredient.Type.Id), nameof(Ingredient.Name)); return(Page()); } _context.Attach(Ingredient).State = EntityState.Modified; _context.Attach(Ingredient.EnergyValue).State = EntityState.Modified; try { await _context.SaveChangesAsync(); await ImageUploader.Upload(_environment, Image, nameof(Ingredients), Ingredient.Id.ToString()); } catch (DbUpdateConcurrencyException) { if (!IngredientExists(Ingredient.Id)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public RatingsController(ApplicationDbContext context, ImageUploader uploader, IB2Client b2Client, IMapper mapper) { _context = context; _uploader = uploader; _b2Client = b2Client; _mapper = mapper; }
public async Task <IActionResult> EditBrand(Brand brand) { ViewBag.CountryList = _countryService.GetCountries().OrderBy(x => x.CountryName); if (!ModelState.IsValid) { return(View()); } var files = HttpContext.Request.Form.Files; var imgFolder = Path.Combine(_appEnvironment.WebRootPath, "images\\upload\\logo"); foreach (var image in files) { try { brand.BrandLogo = await ImageUploader.UploadImage(image, imgFolder).ConfigureAwait(false); } catch (Exception ex) { ModelState.AddModelError("BrandLogo", ex.Message); return(View()); } } _brandService.UpdateBrand(brand); return(RedirectToAction("Brands")); }
public BooksController(IBookStore store, ImageUploader imageUploader, BookDetailLookup bookDetailLookup) { _store = store; _imageUploader = imageUploader; _bookDetailLookup = bookDetailLookup; }
public ActionResult Register(AppUser appUser, HttpPostedFileBase ImagePath) { //validation (doğrulama) kuralları yerine getirilmişse aşağıdaki karar yapısı içerisine girecektir. if (ModelState.IsValid) { if (appUserService.CheckUserName(appUser.Name)) { ViewBag.Exists = "Üye adı daha önce alınmış"; return(View()); } else if (appUserService.CheckEmail(appUser.Email)) { ViewBag.Exists = "Email adresi zaten kayıtlı!"; return(View()); } else { appUser.ID = Guid.NewGuid(); appUser.Role = Role.member; appUser.ActivationCode = Guid.NewGuid(); appUser.ImagePath = ImageUploader.UploadImage("~/Content/images", ImagePath); appUserService.Add(appUser); string message = $"Hoşgeldin {appUser.Name},\nKayıt işlemini tamamlamak için lütfen aşağıdaki bağlantıya tıklayın.\n{Request.Url.Scheme}{System.Uri.SchemeDelimiter}{Request.Url.Authority}/AppUser/Complete/{appUser.ActivationCode}"; MailSender.SendEmail(appUser.Email, "Kayıt talebiniz alındı!", message); return(RedirectToAction("Success", appUser)); } } else { return(View()); } }
public ActionResult UpdateMovie([Bind(Prefix = "Movie")] Movie item, HttpPostedFileBase resim) { item.MovieImagePath = ImageUploader.UploadImage("~/Pictures/", resim); _mvRep.Update(item); return(RedirectToAction("MovieList")); }
public RedirectResult Update(ProductDTO data, HttpPostedFileBase Image) { data.ImagePath = ImageUploader.UploadSingleImage("~/Uploads/", Image); Product product = _productService.GetById(data.Id); if (data.ImagePath == "0" || data.ImagePath == "1" || data.ImagePath == "2") { if (product.ImagePath == "~/Content/Images/TestPhoto.jpg") { data.ImagePath = "~/Content/Images/TestPhoto.jpg"; } else { data.ImagePath = product.ImagePath; } } product.Name = data.Name; product.Price = data.Price; product.UnitsInStock = data.UnitsInStock; product.Quantity = data.Quantity; product.ImagePath = data.ImagePath; product.CategoryID = data.CategoryID; _productService.Update(product); return(Redirect("/Admin/Product/List")); }
public ActionResult Edit([Bind(Include = "Id,Name,CategoryId,Price, Image")] MenuItemSaveViewModel menuItem) { if (ModelState.IsValid) { var item = _db.MenuItems.Find(menuItem.Id); if (item == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } item.Name = menuItem.Name; item.Price = menuItem.Price; item.CategoryId = menuItem.CategoryId; if (menuItem.Image != null && menuItem.Image.ContentLength > 0) { item.Image = ImageUploader.Upload(menuItem.Image); } _db.Entry(item).State = EntityState.Modified; _db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CategoryId = new SelectList(_db.Categories, "Id", "Name", menuItem.CategoryId); return(View(menuItem)); }
public ActionResult Add(Tweet data, HttpPostedFileBase Image) { List <string> UploadedImagePaths = new List <string>(); UploadedImagePaths = ImageUploader.UploadSingleImage(ImageUploader.OriginalProfileImagePath, Image, 1); data.ImagePath = UploadedImagePaths[0]; if (data.ImagePath == "0" || data.ImagePath == "1" || data.ImagePath == "2") { data.ImagePath = ImageUploader.DefaultProfileImagePath; data.ImagePath = ImageUploader.DefaultXSmallProfileImage; data.ImagePath = ImageUploader.DefaulCruptedProfileImage; } else { data.ImagePath = UploadedImagePaths[1]; data.ImagePath = UploadedImagePaths[2]; } data.Status = Core.Enum.Status.Active; data.PublishDate = DateTime.Now; _tweetService.Add(data); return(Redirect("/Admin/Tweet/List")); }
public ActionResult AddProduct(Product product, HttpPostedFileBase resim) { product.ImagePath = ImageUploader.UploadImage("~/Pictures/", resim); _pRep.Add(product); return(RedirectToAction("ProductList")); }
public ActionResult Create([Bind(Include = "Id,Name,CategoryId,Price,Image")] MenuItemSaveViewModel menuItem) { if (menuItem.Image == null || menuItem.Image.ContentLength == 0) { ModelState.AddModelError("Image", "Please select an image to upload."); } else if (!ImageUploader.IsValidImageType(menuItem.Image)) { ModelState.AddModelError("Image", "The file you are attempting to upload is not an image."); } if (ModelState.IsValid) { var imageUrl = ImageUploader.Upload(menuItem.Image); _db.MenuItems.Add(new MenuItem() { Name = menuItem.Name, Price = menuItem.Price, CategoryId = menuItem.CategoryId, Image = imageUrl }); _db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CategoryId = new SelectList(_db.Categories, "Id", "Name", menuItem.CategoryId); return(View(menuItem)); }
public ActionResult AddEmployee(Employee employee, HttpPostedFileBase resim) { //TODO: Dosya yolunu değiştiremiyorum ve güncellenmede resim kayboluyor employee.Photo = ImageUploader.UploadImage("~/Pictures/", resim); eRep.Add(employee); return(RedirectToAction("EmployeeList")); }
public ActionResult Update(Car model, HttpPostedFileBase Image) { try { model.ImageUrl = ImageUploader.UploadImage("~/Uploads", Image); if (model.ImageUrl == "1" || model.ImageUrl == "2" || model.ImageUrl == "0") { model.ImageUrl = "/Content/Images/reaper_cute.png"; } Car arac = _carService.GetById(model.Id); arac.CModel = model.CModel; arac.CarBrandID = model.CarBrandID; arac.CostPerDay = model.CostPerDay; arac.PersonCapacity = model.PersonCapacity; arac.BaggageCapacity = model.BaggageCapacity; arac.MinRentAge = model.MinRentAge; arac.Gearbox = model.Gearbox; arac.FuelType = model.FuelType; arac.ImageUrl = model.ImageUrl; _carService.Update(arac); TempData["CarMsg"] = "Güncelleme işlemi gerçekleştirilmiştir"; return(RedirectToAction("List", "Car", new { area = "Admin" })); } catch (Exception ex) { TempData["Err"] = "Güncelleme gerçekleştirilemedi \n" + ex.Message; return(RedirectToAction("List", "Car", new { area = "Admin" })); } }
public async Task <IActionResult> Edit(int id, StudentViewModel studentViewModel) { var studentInDB = await _context.Students.FindAsync(id); studentInDB.FirstName = studentViewModel.Student.FirstName; studentInDB.LastName = studentViewModel.Student.LastName; studentInDB.ClassOfEntryId = studentViewModel.Student.ClassOfEntryId; studentInDB.DateOfBirth = studentViewModel.Student.DateOfBirth; studentInDB.PhoneNumber = studentViewModel.Student.PhoneNumber; studentInDB.PermanentAddress = studentViewModel.Student.PermanentAddress; studentInDB.Sex = studentViewModel.Student.Sex; studentInDB.StateOfOrigin = studentViewModel.Student.StateOfOrigin; studentInDB.Religion = studentViewModel.Student.Religion; studentInDB.NameOfGuardianOrParent = studentViewModel.Student.NameOfGuardianOrParent; var webRootPath = _hostingEnvironment.WebRootPath; studentInDB.Photo = ImageUploader.UploadImageToServer(studentInDB.Photo, HttpContext.Request.Form.Files, webRootPath); await _context.SaveChangesAsync(); TempData["StudentSaved"] = Constant.Updated; TempData.Keep(); return(RedirectToAction("Index")); }
public ActionResult Register(AppUser model, HttpPostedFileBase ImagePath) { if (ModelState.IsValid) { if (appUser.Any(x => x.UserName == model.UserName)) { ViewBag.ExistsUser = "******"; return View(); } else if (appUser.Any(x => x.Email == model.Email)) { ViewBag.ExistsEmail = "Email daha önce kayıt edilmiş."; return View(); } else { model.ImagePath = ImageUploader.UploadSingleImage("~/Uploads/Users/", ImagePath); model.ID = Guid.NewGuid(); appUser.Add(model); string sendMessage = "Tebrikler hesabınız oluşturuldu. Hesabınızı Aktive etmek için http://localhost:50247/Home/Aktivasyon/" + model.ActivationCode; string _subject = $"Hoşgeldin {model.UserName}"; MailSender.Send(model.Email, sendMessage, _subject); return View("RegisterOk"); } } else { return View(); } }
protected void Button2_Click(object sender, EventArgs e) { _imageUploader = new ImageUploader("restaurant23"); string fileName; try { if (FileUpload1.HasFile) { fileName = FileUpload1.FileName; HttpPostedFile image = FileUpload1.PostedFile; _imageUploader.UploadImage(image, fileName); upload.Text = "File Uploaded Successfully"; } } catch (Exception ex) { upload.Text = "File Upload Error"; //ExceptionLogging.SendExcepToDB(ex); } }
public ActionResult Add(Product product, HttpPostedFileBase ImagePath) { if (ModelState.IsValid) { product.ImagePath = ImageUploader.UploadImage("~/Content/images", ImagePath); if (product.ImagePath == "0") { ViewBag.Error = "Dosya Boş"; } else if (product.ImagePath == "1") { ViewBag.Error = "Zaten bu isimde dosya bulunmaktadır"; } else if (product.ImagePath == "2") { ViewBag.Error = "Dosya uzantısı belirtilenlere uymuyor"; } else { ViewBag.Produts = productService.GetAll(); productService.Add(product); return(RedirectToAction("Index")); } } return(View()); }
public CreateModel(ApplicationDbContext context, ImageUploader uploader, OgmaConfig config, NotificationsRepository notificationsRepo) { _context = context; _uploader = uploader; _config = config; _notificationsRepo = notificationsRepo; }
public JsonResult UploadRealtyImage() { var file = Request.Files.Get("myfile"); var uploader = new ImageUploader(file); var result = new { filename = uploader.Name, contentType = uploader.ContentType, contentLength = uploader.ContentLength, newFilename = uploader.UniqueName }; try { uploader.Save("realty"); uploader.Convert(ProjectConfiguration.Get.RealtyImageWidth, ProjectConfiguration.Get.RealtyImageHeight); uploader.Save("realty_thumb"); } catch (Exception) { return(Json(new { status = "fail" }, "text/html")); } return(Json(result, "text/html")); }
public ActionResult Update(AppUserDTO data, HttpPostedFileBase Image) { data.ImagePath = ImageUploader.UploadSingleImage("~/Uploads", Image); AppUser user = service.AppUserService.GetById(data.Id); if (data.ImagePath == "0" || data.ImagePath == "1" || data.ImagePath == "2") { if (user.ImagePath == null || user.ImagePath == "~/Content/Images/avantaj.png") { data.ImagePath = "~/Content/Images/avantaj.png"; } else { data.ImagePath = user.ImagePath; } } user.UserName = data.UserName; user.Password = data.Password; user.Role = data.Role; user.ImagePath = data.ImagePath; user.Email = data.Email; service.AppUserService.Update(user); return(Redirect("/Admin/AppUser/ListMember")); }
public ActionResult RegisterComplete(User model, HttpPostedFileBase ImagePath) { if (ModelState.IsValid) { if (db.Any(x => x.UserName == model.OgrenciTCKimlikNumarasi)) { ViewBag.ExistsUser = "******"; return(View()); } else if (db.Any(x => x.Password == model.OkulNumarasi.ToString())) { ViewBag.ExistsPassword = "******"; return(View()); } else { model.ID = Guid.NewGuid(); model.ActivationCode = Guid.NewGuid(); model.IsActive = false; model.ImagePath = ImageUploader.UploadSingleImage("~/Uploads/Users/", ImagePath); db.Add(model); string message = $"Hoşgeldin {model.UserName},\n\nKayıt işlemini tamamlamak için lütfen aşağıdaki bağlantıya tıklayın.\n\n{Request.Url.Scheme}{System.Uri.SchemeDelimiter}{Request.Url.Authority}/Admin/Account/Complete/{model.ActivationCode}"; MailSender.SendEmail(model.Email, "Kayıt talebiniz alındı", message); return(RedirectToAction("Success,Account")); } } else { return(View()); } }
public ActionResult AddTweet(Tweet data, HttpPostedFileBase Image) { List <string> UploadedImagePaths = new List <string>(); UploadedImagePaths = ImageUploader.UploadSingleImage(ImageUploader.OriginalProfileImagePath, Image, 1); data.ImagePath = UploadedImagePaths[0]; if (data.ImagePath == "0" || data.ImagePath == "1" || data.ImagePath == "2") { data.ImagePath = ImageUploader.DefaultProfileImagePath; data.ImagePath = ImageUploader.DefaultXSmallProfileImage; data.ImagePath = ImageUploader.DefaulCruptedProfileImage; } else { data.ImagePath = UploadedImagePaths[1]; data.ImagePath = UploadedImagePaths[2]; } AppUser user = _appUserService.GetByDefault(x => x.UserName == User.Identity.Name); data.AppUserID = user.ID; data.CreatedDate = DateTime.Now; _tweetService.Add(data); return(Redirect("/Member/Home/Index")); }
public ActionResult Add(AppUser data, HttpPostedFileBase Image) { List <string> UploadedImagePaths = new List <string>(); UploadedImagePaths = ImageUploader.UploadSingleImage(ImageUploader.OriginalProfileImagePath, Image, 1); data.UserImage = UploadedImagePaths[0]; if (data.UserImage == "0" || data.UserImage == "1" || data.UserImage == "2") { data.UserImage = ImageUploader.DefaultProfileImagePath; data.XSmallUserImage = ImageUploader.DefaultXSmallProfileImage; data.CruptedUserImage = ImageUploader.DefaulCruptedProfileImage; } else { data.XSmallUserImage = UploadedImagePaths[1]; data.CruptedUserImage = UploadedImagePaths[2]; } data.Status = MaterialManagemenetProject.Core.Enum.Status.Active; _appUserService.Add(data); return(Redirect("/Admin/AppUser/List")); }
public async Task <IActionResult> Edit(int id, [Bind("Id,CategoryId,Name,Price,ImgFile")] Product product) { if (id != product.Id) { return(NotFound()); } if (ModelState.IsValid) { try { if (product.ImgFile != null) { product.ImgUrl = await ImageUploader.UploadImage(product.ImgFile); } _context.Update(product); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(product.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["CategoryId"] = new SelectList(_context.Category, "Id", "Name", product.CategoryId); return(View(product)); }
public ActionResult Create(AppUser model, HttpPostedFileBase ImagePath) { model.ID = Guid.NewGuid(); model.ImagePath = ImageUploader.UploadSingleImage("~/Uploads/Users/", ImagePath); appUser.Add(model); return(RedirectToAction("Index")); }
public virtual ActionResult UploadFile() { Project project = _projectRepo.GetProjectById(1); IPathResolver pathResolver = new ProjectAvatarPathResolver("D:\\TestHome", project); IFileUploader fileUploader = new ImageUploader(new AvatarImageProfile()); UploadManager uploader = new UploadManager(Request, pathResolver, fileUploader); uploader.Upload(); return View(); }
public TCPClient(ImageUploader imageUploader) { uploader = imageUploader; client = new TcpClient(); }