public ActionResult EditPicture(PictureViewModel model, HttpPostedFileBase file)
        {
            string pictureFolder = Server.MapPath("../../Images");

            var path     = string.Empty;
            var fileName = string.Empty;

            if (file != null && file.ContentLength > 0)
            {
                fileName = model.UserID + model.GalleryID + Path.GetFileName(file.FileName);
                path     = Path.Combine(pictureFolder, fileName);

                file.SaveAs(path);

                model.Path = "~/Images/" + fileName;

                RemoveOldFileIfExists(model);
            }
            model.DateEdited = DateTime.Now;
            if (ModelState.IsValid)
            {
                var picToUpdate = EntityModelMapper.ModelToEntity(model);
                repo.AddOrUpdate(picToUpdate);
                return(RedirectToAction("Details", "Picture", model));
            }

            ModelState.AddModelError("", "Couldn't update information");
            return(View(model));
        }
Beispiel #2
0
        public ActionResult Create(PhotoModel photo, HttpPostedFileBase[] filesToBeUploaded)
        {
            //why is the photo id and album id same?
            int albumId = photo.PhotoModelId;

            AlbumModel album = EntityModelMapper.EntityToModel(AlbumRepo.Get(albumId));

            foreach (var file in filesToBeUploaded)
            {
                //set important properties of the new photo object
                PhotoModel currentPhoto = new PhotoModel()
                {
                    //PhotoId = Guid.NewGuid(),
                    Name        = photo.Name,
                    FileName    = file.FileName,
                    DateCreated = DateTime.Now,
                    Description = "[no description set]",
                    UploadedBy  = album.User.Username,
                    Comments    = new List <CommentModel>(),
                };

                //physically saves copie(s) of the photos to the path specified
                file.SaveAs(Server.MapPath("~/UsersData/" + album.User.Username + "/" + album.Name + "/" + file.FileName));

                //saves the photo object to the album object
                //todo: should not this be saved to the static list of a users album photos immediately?
                album.Photos.Add(currentPhoto);
            }
            ;
            return(RedirectToAction("Index", "Home"));
            //return PartialView("_Photos",/*allphotos*/);
        }
Beispiel #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="configureByCode">optional, supply custom configuration by code or leave null to look for configuration file</param>
        /// <param name="schemaExportPath">optional, supply a path to export schema and hbm.xml files. NOT for production use.</param>
        /// <param name="exposeCfg">optional, NH configuration is exposed after configured and schema exported.</param>
        /// <returns></returns>
        public static ISessionFactory BuildSessionFactory(Action <Configuration> configureByCode = null, string schemaExportPath = null, Action <Configuration> exposeCfg = null)
        {
            var configAction = configureByCode ?? (x => x.Configure());

            var cfg = new Configuration();

            configAction(cfg);

            var entityMappings = new EntityModelMapper().CompileMappings();

            cfg.AddMapping(entityMappings);

            if (!string.IsNullOrEmpty(schemaExportPath))
            {
                ExportSchema(cfg, schemaExportPath);
                ExportHbmMappingsXml(entityMappings, "Entity", schemaExportPath);
            }

            cfg.SetInterceptor(new UtcDateTimeInterceptor());

            if (exposeCfg != null)
            {
                exposeCfg(cfg);
            }

            return(cfg.BuildSessionFactory());
        }
        public ActionResult Registration(UserViewModel user)
        {
            user.guid = Guid.NewGuid();

            if (ModelState.IsValid && !repo.isEmailTaken(user.Email))
            {
                var newUser = EntityModelMapper.ModelToEntity(user);

                repo.AddOrUpdate(newUser);

                if (Request.IsAjaxRequest())
                {
                    return(Content("Login"));
                }
                return(Redirect("/Auth/Login"));
            }



            ModelState.AddModelError("", "Something went wrong");

            if (Request.IsAjaxRequest())
            {
                return(Content("Invalid information!"));
            }
            return(View(user));
        }
Beispiel #5
0
        public ActionResult GalleryList()
        {
            var galleryList = new List <GalleryViewModel>();

            foreach (var gallery in repo.All())
            {
                galleryList.Add(EntityModelMapper.EntityToModel(gallery));
            }


            return(PartialView("_GalleryListView", galleryList));
        }
        public ActionResult Show(GalleryViewModel model)
        {
            var pictures       = new List <PictureViewModel>();
            var picturesFromDB = repo.All().Where(x => x.GalleryID == model.id);

            foreach (var pic in picturesFromDB)
            {
                pictures.Add(EntityModelMapper.EntityToModel(pic));
            }
            ViewBag.GalleryName = model.GalleryName;
            return(View(pictures));
        }
Beispiel #7
0
        public ActionResult Index()
        {
            List <AlbumEntity> albumEntities = AlbumRepo.GetAll();

            List <AlbumModel> albumModels = new List <AlbumModel>();

            foreach (var albumEntity in albumEntities)
            {
                albumModels.Add(EntityModelMapper.EntityToModel(albumEntity));
            }

            return(View(albumModels));
        }
        public ActionResult Edit(int id)
        {
            var model = new PictureViewModel();

            var picFromDB = repo.ByID(id);

            if (picFromDB != null)
            {
                model = EntityModelMapper.EntityToModel(picFromDB);
            }

            return(View(model));
        }
Beispiel #9
0
        public ActionResult Index()
        {
            List <PhotoEntity> photoEntities = PhotoRepo.RetrieveAll();

            List <PhotoModel> photoModels = new List <PhotoModel>();

            foreach (var photoEntity in photoEntities)
            {
                photoModels.Add(EntityModelMapper.EntityToModel(photoEntity));
            }

            return(View(photoModels));
        }
        // GET: Home
        public ActionResult Index()
        {
            var newestPictures = new List <PictureViewModel>();
            var picturesFromDB = repo.All().OrderByDescending(x => x.DatePosted).Take(5).ToList();

            foreach (var pic in picturesFromDB)
            {
                newestPictures.Add(EntityModelMapper.EntityToModel(pic));
            }


            return(View(newestPictures));
        }
Beispiel #11
0
        public ActionResult Index()
        {
            List <UserEntity> userEntities = UserRepository.RetrieveAll();

            List <UserModel> userModels = new List <UserModel>();

            foreach (var userEntity in userEntities)
            {
                userModels.Add(EntityModelMapper.EntityToModel(userEntity));
            }

            return(View(userModels));
        }
        public ActionResult Comments(int pictureID)
        {
            var comments = new List <CommentViewModel>();


            var commentsFromDB = repo.All().Where(x => x.PictureID == pictureID);

            foreach (var comment in commentsFromDB)
            {
                comments.Add(EntityModelMapper.EntityToModel(comment));
            }


            return(PartialView(comments));
        }
Beispiel #13
0
        public ActionResult Index(AlbumModel album, string albumComment)
        {
            CommentModel commentModel = new CommentModel()
            {
                Comment     = albumComment,
                DateCreated = DateTime.Now,
                Album       = album,
            };

            var commentEntity = EntityModelMapper.ModelToEntity(commentModel);

            CommentRepo.NewAlbumComment(album.AlbumModelId, commentEntity);

            return(View(AlbumRepo.GetAll()));
        }
Beispiel #14
0
        public ActionResult Login(UserModel userModel)
        {
            UserModel authenticatedUser = EntityModelMapper.EntityToModel(
                UserRepository.RetrieveLoggedInUser(
                    userModel.Username, userModel.Password));

            if (authenticatedUser != null)
            {
                return(Content("Successfull Login"));
            }
            else
            {
                return(Content("Login failed"));
            }
        }
Beispiel #15
0
        public ActionResult Details(PhotoModel photo, string comment)
        {
            PhotoModel photoToCommentOn = EntityModelMapper.EntityToModel(PhotoRepo.GetPhoto(photo.PhotoModelId));

            CommentModel newComment = new CommentModel()
            {
                //CommentId = Guid.NewGuid(),
                Comment     = comment,
                DateCreated = DateTime.Now,
                //Photo = photo,
            };

            photoToCommentOn.Comments.Add(newComment);

            return(View(photoToCommentOn));
        }
Beispiel #16
0
        public ActionResult Register(UserModel userModel)
        {
            if (ModelState.IsValid)
            {
                if (userModel != null)
                {
                    //todo: create growl when user gets registered

                    UserRepository.Add(EntityModelMapper.ModelToEntity(userModel));

                    return(RedirectToAction("Index", "Home"));
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(userModel));
        }
Beispiel #17
0
        public ActionResult Create(GalleryViewModel model)
        {
            if (User.Identity.IsAuthenticated)
            {
                var identity = (ClaimsIdentity)User.Identity;
                int?userID   = int.Parse(Helpers.GetSid(identity));
                if (userID != null)
                {
                    model.DateCreated = DateTime.Now;
                    model.UserID      = (int)userID;

                    var entity = EntityModelMapper.ModelToEntity(model);
                    repo.AddOrUpdate(entity);
                }
                return(RedirectToAction("Index", "Gallery"));
            }
            return(Redirect(Request.UrlReferrer.ToString()));
        }
Beispiel #18
0
        public ActionResult Index()
        {
            var galleries = new List <GalleryViewModel>();

            var galleriesFromDB = repo.All();

            if (galleriesFromDB != null)
            {
                foreach (var gallery in galleriesFromDB)
                {
                    var galleryToAdd = EntityModelMapper.EntityToModel(gallery);
                    galleries.Add(galleryToAdd);
                }
            }


            return(View(galleries));
        }
        public ActionResult NewComment(CommentViewModel model)
        {
            var identity = (ClaimsIdentity)User.Identity;
            var sid      = identity.Claims.First(x => x.Type == ClaimTypes.Sid);

            model.UserID = int.Parse(sid.Value);

            model.DatePosted = DateTime.Now;


            if (ModelState.IsValid && User.Identity.IsAuthenticated)
            {
                var newComment = EntityModelMapper.ModelToEntity(model);
                repo.AddOrUpdate(newComment);
                return(Content("Comment added"));
            }

            return(Content("Couldn't add comment"));
        }
        public ActionResult Index()
        {
            if (User.Identity.IsAuthenticated)
            {
                var identity = (ClaimsIdentity)User.Identity;
                var sid      = identity.Claims.First(x => x.Type == ClaimTypes.Sid);
                int userID   = int.Parse(sid.Value);


                var userFromDB = repo.ByID(userID);

                if (userFromDB != null)
                {
                    var user = EntityModelMapper.EntityToModel(userFromDB);
                    return(View(user));
                }
            }

            return(RedirectToAction("Login", "Auth"));
        }
Beispiel #21
0
        public ActionResult ViewGallery(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction("Index"));
            }

            GalleryViewModel galleryToView = null;

            var galleryID = (int)id;

            galleryToView = EntityModelMapper.EntityToModel(repo.ByID(galleryID));


            if (galleryToView != null)
            {
                return(View(galleryToView));
            }

            return(RedirectToAction("Index"));
        }
        public ActionResult Create(PictureViewModel model, HttpPostedFileBase photo)
        {
            Thread.Sleep(5000);
            model.UserID     = int.Parse(MVCLabb.Utilities.Helpers.GetSid(User.Identity));
            model.DatePosted = DateTime.Now;
            string pictureFolder = Server.MapPath("~/Images");

            var path     = string.Empty;
            var fileName = string.Empty;

            if (photo != null && photo.ContentLength > 0)
            {
                fileName = model.UserID + model.GalleryID + Path.GetFileName(photo.FileName);
                if (!Helpers.IsFilePicture(fileName))
                {
                    return(Content("The file must be a picture in the format png, jpg or jpeg"));
                }
                path = Path.Combine(pictureFolder, fileName);
                photo.SaveAs(path);
            }
            else
            {
                return(Content("You must choose a file!"));
            }


            model.Path = "~/Images/" + fileName;



            if (ModelState.IsValid)
            {
                var newPicture = EntityModelMapper.ModelToEntity(model);
                repo.AddOrUpdate(newPicture);
                return(Content("Added picture to gallery!"));
                //return RedirectToAction("ViewGallery", "Gallery", new { id = model.GalleryID });
            }
            return(Content("Something went wrong couldn't add the picture"));
        }
Beispiel #23
0
        public ActionResult Create(AlbumModel albumModel)
        {
            try
            {
                int userId = albumModel.AlbumModelId; //TODO: userid and albumid the same? why?

                var albumEntity = EntityModelMapper.ModelToEntity(albumModel);

                //albumEntity.User = UserRepo.GetUser(userId);

                AlbumRepo.Add(albumEntity, userId);//adds new album to dbset(database)

                //create directory for new albums photos
                string newAlbumPath = Server.MapPath("~/UsersData/" + albumEntity.User.Username + "/" + albumEntity.Name);

                Directory.CreateDirectory(newAlbumPath);

                return(RedirectToAction("Index", "User"));
            }
            catch
            {
                return(View());
            }
        }
        public ActionResult Details(PictureViewModel picture)
        {
            var pictureModel = EntityModelMapper.EntityToModel(repo.ByID(picture.id));

            return(View(pictureModel));
        }
Beispiel #25
0
        public ActionResult Details(PhotoModel photo)
        {
            PhotoModel photoToDisplay = EntityModelMapper.EntityToModel(PhotoRepo.GetPhoto(photo.PhotoModelId));

            return(View(photoToDisplay));
        }
Beispiel #26
0
        public ActionResult Details(int id)//this id has to match the routeconfig id name!
        {
            UserModel userToShow = EntityModelMapper.EntityToModel(UserRepository.GetUser(id));

            return(View(userToShow));
        }