public PartialViewResult Load(HttpPostedFileBase file) { if (file != null) { _imageController = new ImageController(); //get the bytes from the uploaded file byte[] data = _imageController.GetBytesFromFile(file); using (IDal dal = new Dal()) { dal.addImage(data, ""); } } return PartialView(); }
public ActionResult RegisterAdvertisement(AdvertisementModel model, HttpPostedFileBase file) { if (Request.IsAuthenticated) { if (ModelState.IsValid) { string userId = User.Identity.GetUserId(); //animal AnimalModel animal = new AnimalModel { name = model.animal.race, type = model.animal.type, race = model.animal.race }; if (file != null) { _imageController = new ImageController(); animal.photo = new List<ImageModel> { _imageController.GetImage(file) }; } using (IDal dal = new Dal()) dal.addAdvertissement(DateTime.Now, model.title, model.description, animal, userId); return RedirectToAction("RegisterAdvertisement", new { Message = AdvertisementMessageId.AddAdvertiseSuccess }); } else return View(model); } else return RedirectToAction("Login", "Account"); }
public async Task<ActionResult> Register(RegisterViewModel model, HttpPostedFileBase file) { if (ModelState.IsValid) { if (file != null) { _imageController = new ImageController(); model.Image = _imageController.GetImage(file); } var user = new ApplicationUser { UserName = model.Email , Email = model.Email , Name = model.Name, LastName = model.LastName, Birthdate = model.Birthdate, PhoneNumber = model.PhoneNumber, Adress = model.Adress, Image = model.Image }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false); return RedirectToAction("Index", "Home"); } AddErrors(result); } return View(model); }