public ActionResult EditPhoto(PhotoVM model, HttpPostedFileBase file) { string photoFolder = Server.MapPath("../../Images"); var path = string.Empty; var fileName = string.Empty; if (file != null && file.ContentLength > 0) { fileName = "pc" + model.id + "al" + model.AlbumID + Path.GetFileName(file.FileName); path = Path.Combine(photoFolder, fileName); file.SaveAs(path); model.Path = "~/Images/" + fileName; RemoveOldFileIfExists(model); } model.DateEdited = DateTime.Now; if (ModelState.IsValid) { var photoToUpdate = ModelMapper.ModelToEntity(model); repo.AddOrUpdate(photoToUpdate); return(RedirectToAction("Details", "Photo", model)); } ModelState.AddModelError("", "gick inte att uppdatera info"); return(View(model)); }
public async Task <IViewComponentResult> InvokeAsync(Paging pm) { if (pm == null) { pm = new Paging(); } var vm = new PhotoVM(); var skipCount = (pm.Page == 1) ? 0 : (pm.Page - 1) * pageSize; var searchQuery = ListHelper.GenerateSearchQuery(pm.SearchParams); var sorting = ListHelper.GenerateSortQuery(pm.SortParams); vm.Search = pm.SearchParams; vm.Sort = pm.SortParams; vm.List = await _uow.Repository <Photos>() .Query(new EfConfig()) .Include(x => x.Album) .Where(searchQuery) .OrderBy(sorting) .Skip(skipCount) .Take(pageSize) .ToListAsync(); ListHelper.Paging <Photos>(vm, pageSize, pm.Page, searchQuery, null); return(View(vm)); }
public ActionResult NewComment(PhotoVM photo) { var newComment = new CommentsVM(); newComment.PhotoID = photo.id; return(View(newComment)); }
public ActionResult Create(AlbumVM model) { PhotoVM p = new PhotoVM(); p.AlbumID = model.id; p.Name = ""; p.Description = ""; return(View(p)); }
public ActionResult Add() { PhotoVM photoVM = new PhotoVM() { Categories = _PhotoCategoryService.GetActive() }; return(View(photoVM)); }
public ActionResult ListByCategory(int id) { PhotoVM photoVM = new PhotoVM() { Photos = _PhotoService.GetActive().Where(x => x.PhotoCategoryID == id).ToList(), CategoryName = _PhotoCategoryService.GetByDefault(x => x.ID == id).Name, }; return(View(photoVM)); }
// GET: Product/Shortly/5 public ActionResult Shortly(/*Guid id*/) { //ProductVM model = productRep.Get(id); ProductVM model = productRep.GetAll().First(); PhotoVM prima = photoRep.FindBy(p => p.PrimePhoto == true || p.ProductId == model.ProductId).First(); ViewBag.prima = prima.PhotoURL; return(View(model)); }
private static Photo ConvertPhotoVMtoPhoto(PhotoVM vmPhoto) { Photo photo = new Photo() { PhotoId = vmPhoto.PhotoId, ImageMimeType = vmPhoto.ImageMimeType, ImageData = vmPhoto.ImageData }; return(photo); }
public ActionResult Show(int id) { PhotoVM photoVM = new PhotoVM() { Photo = _PhotoService.GetByID(id), Photos = _PhotoService.GetActive().Take(10).OrderByDescending(x => x.AddDate).ToList(), Categories = _PhotoCategoryService.GetActive().Take(10).OrderByDescending(x => x.Name).ToList(), UserName = _PhotoService.GetByID(id).User.UserName }; return(View(photoVM)); }
public async Task <ActionResult> Form(PhotoVM vm) { //var qs = Request.UrlReferrer.Query.ToString(); if (ModelState.IsValid) { if (vm.Photo.Id > 0) { var existing = await _uow.Repository <Photos>() .Query(x => x.Id == vm.Photo.Id, new EfConfig()) .FirstOrDefaultAsync(); if (existing != null) { try { _uow.Repository <Photos>().QuickUpdate(existing, vm.Photo); await _uow.SaveChangesAsync(); TempData["PageStates"] = (int)PageStatesEnum.Updated; } catch (Exception ex) { TempData["PageStates"] = (int)PageStatesEnum.NotUpdated; var msg = ex.Message; // error log } } } else { try { _uow.Repository <Photos>().Add(vm.Photo); await _uow.SaveChangesAsync(); TempData["PageStates"] = (int)PageStatesEnum.Created; return(Redirect(Url.Action("Form", new { id = vm.Photo.Id }))); //return Redirect(Url.Action("Form", new { id = vm.XmlRule.Id }) + qs); } catch (Exception ex) { TempData["PageStates"] = (int)PageStatesEnum.NotCreated; var msg = ex.Message; // error log } } } //await FormInit(vm); return(View(vm)); }
public async Task <IViewComponentResult> InvokeAsync(string id) { AppUser user = await _db.Users.FindAsync(id); PhotoVM model = new PhotoVM { user = user, Photos = _db.Photos.Where(p => p.user.Id == user.Id) }; return(View(await Task.FromResult(model))); }
public async Task <IActionResult> Photos(string id) { AppUser user = await _db.Users.FindAsync(id); PhotoVM model = new PhotoVM { user = user, Photos = _db.Photos.Where(p => p.user == user) }; return(View(model)); }
public ActionResult Edit(int id) { var model = new PhotoVM(); var photoFromDB = repo.ByID(id); if (photoFromDB != null) { model = ModelMapper.EntityToModel(photoFromDB); } return(View(model)); }
private void RemoveOldFileIfExists(PhotoVM photo) { var oldphoto = repo.ByID(photo.id); if (oldphoto.Path != photo.Path) { var oldPhysicalPath = Request.MapPath(oldphoto.Path); FileInfo oldfile = new FileInfo(oldPhysicalPath); if (oldfile.Exists) { oldfile.Delete(); } } }
private string UploadedFile(PhotoVM model) { string uniqueFileName = null; if (model.ProfilePicture != null) { string uploadsFolder = Path.Combine(webHostEnvironment.WebRootPath, "images"); uniqueFileName = Guid.NewGuid().ToString() + "_" + model.ProfilePicture.FileName; string filePath = Path.Combine(uploadsFolder, uniqueFileName); using (var fileStream = new FileStream(filePath, FileMode.Create)) { model.ProfilePicture.CopyTo(fileStream); } } return(uniqueFileName); }
public ActionResult Create(PhotoVM model, HttpPostedFileBase photo) { Thread.Sleep(5000); var identity = User.Identity.Name; int?userID = Userrepo.GetID(identity); model.UserID = (int)userID; model.DatePosted = DateTime.Now; string photoFolder = Server.MapPath("~/Images"); var path = string.Empty; var fileName = string.Empty; if (photo != null && photo.ContentLength > 0) { var rek = repo.GetNewIndex(); fileName = "pc" + rek + "al" + model.AlbumID + Path.GetFileName(photo.FileName); if (!Helpers.IsFilePhoto(fileName)) { return(Content("Filen måste ha formatet png, jpg or jpeg")); } path = Path.Combine(photoFolder, fileName); photo.SaveAs(path); } else { return(Content("Du måste välja en fil!")); } model.Path = "~/Images/" + fileName; if (ModelState.IsValid) { var newPhoto = ModelMapper.ModelToEntity(model); repo.AddOrUpdate(newPhoto); return(Content("Added fil")); //return Json(Url.Action("ViewAlbum", "Album", new { id = model.AlbumID })); } var result1 = "nånting gick fel"; return(Json(Request.UrlReferrer.ToString())); }
public ActionResult Add(PhotoVM _Photo, HttpPostedFileBase image) { _Photo.Photo.UserID = _UserService.GetByDefault(x => x.UserName == User.Identity.Name).ID; if (image == null) { return(View()); } else { _Photo.Photo.Url = new byte[image.ContentLength]; image.InputStream.Read(_Photo.Photo.Url, 0, image.ContentLength); _Photo.Photo.Name = image.FileName; _Photo.Photo.PhotoCategoryID = _PhotoCategoryService.GetByDefault(x => x.Name == _Photo.CategoryName).ID; _PhotoService.Add(_Photo.Photo); } return(Redirect("/SysAdmin/Photo/List")); }
public static PhotoDataModel ModelToEntity(PhotoVM model) { PhotoDataModel entity = new PhotoDataModel(); entity.Name = model.Name; entity.ID = model.id; entity.Path = model.Path; entity.UserID = model.UserID; entity.Description = model.Description; entity.Datecreated = model.DatePosted; entity.Dateupdated = model.DateEdited; entity.AlbumID = model.AlbumID; entity.publik = model.IsPublicPhoto; return(entity); }
private static PhotoVM ConvertPhotoToPhotoVM(Photo photo, bool isPrivate) { if (photo != null) { PhotoVM photoView = new PhotoVM() { PhotoId = photo.PhotoId, ImageMimeType = photo.ImageMimeType, }; if (!isPrivate) { photoView.ImageData = photo.ImageData; } return(photoView); } return(null); }
public async Task <IActionResult> Form(int id) { var vm = new PhotoVM { ToolBar = new ToolbarAuth(), Photo = new Photos() }; if (id > 0) { vm.Photo = await _uow.Repository <Photos>() .Query(x => x.Id == id, new EfConfig()) .FirstOrDefaultAsync(); } //await FormInit(vm); return(View(vm)); }
public async Task <IActionResult> Create(PhotoVM model) { if (ModelState.IsValid) { string uniqueFileName = UploadedFile(model); Produkt produkt = new Produkt { Ime = model.Ime, NamenetoZa = model.NamenetoZa, Cena = model.Cena, ProfilePicture = uniqueFileName, }; _context.Add(produkt); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(model)); }
public async Task <ActionResult> Details(string name) { string photoContainer = CloudConfigurationManager.GetSetting("storage:photocontainer"); CloudBlobClient client = _account.CreateCloudBlobClient(); CloudBlobContainer container = client.GetContainerReference(photoContainer); var blob = container.GetBlockBlobReference(name); try { await blob.FetchAttributesAsync(); } catch (StorageException e) { if (e.RequestInformation.HttpStatusCode == (int)HttpStatusCode.NotFound) { return(HttpNotFound("Image does not exist")); } throw; } var comments = await _context.GetAllAsync(x => x.PictureId == name); var vm = new PhotoVM() { PictureUrl = blob.Uri.ToString(), PictureName = blob.Name, Caption = blob.Metadata.ContainsKey("Caption") ? blob.Metadata["Caption"] : blob.Name, Tags = blob.Metadata.Where(x => x.Key.StartsWith("Tag")).Select(x => x.Value).ToList(), Comments = comments?.OrderByDescending(entity => entity.Created).Select(c => new CommentVM { Created = c.Created, Message = c.Message, ProfileUrl = c.ProfileUrl, UserId = c.UserId }).ToList() }; return(View(vm)); }
public static PhotoVM EntityToModel(PhotoDataModel entity) { PhotoVM model = new PhotoVM(); model.Name = entity.Name; model.id = entity.ID; model.Path = entity.Path; model.UserID = entity.UserID; model.Description = entity.Description; model.DatePosted = entity.Datecreated; model.DateEdited = entity.Dateupdated; model.AlbumID = entity.AlbumID; model.IsPublicPhoto = entity.publik; entity.User = repouser.ByID((int)entity.UserID); model.User = EntityToModel(entity.User); model.Uploader = entity.User.FirstName + " " + entity.User.LastName; return(model); }
public ActionResult Delete(PhotoVM model) { return(View(model)); }
public ActionResult Details(PhotoVM photo) { var photoModel = ModelMapper.EntityToModel(repo.ByID(photo.id)); return(View(photoModel)); }