Пример #1
0
        public ActionResult Create(GigsFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Genres = _unitOfWork.Genres.GetGenres();

                return(View("GigForm", viewModel));
            }


            var gig = new Gig
            {
                ArtistId = User.Identity.GetUserId(),
                DateTime = viewModel.GetDateTime(),
                Venue    = viewModel.Venue,
                GenreId  = viewModel.GenreId
            };


            _unitOfWork.Gigs.Add(gig);


            _unitOfWork.Complete();


            return(RedirectToAction("Mine", "Gigs"));
        }
Пример #2
0
        private void CreateOrModifyAGig(GigsFormViewModel model)
        {
            if (model.UserAction == New)
            {
                // Create a new gig object.
                var gig = new Gig
                {
                    ArtistId = _userManager.GetUserId(User), DateTime = model.GetDateTime(), GenreId = model.Genre,
                    Venue    = model.Venue, ImageUrl = _uniqueImageName
                };

                // Add gig object into gig collections.
                _unitOfWork.Gigs.AddAGig(gig);
            }
            else
            {
                // Modify a gig object.
                var gigInDb = _unitOfWork.Gigs.FindGigById(model.GigId);
                gigInDb.DateTime = model.GetDateTime();
                gigInDb.Venue    = model.Venue;
                gigInDb.GenreId  = model.Genre;
                if (model.Photo != null)
                {
                    if (gigInDb.ImageUrl != null)
                    {
                        var oldImage = Path.Combine(_hostEnvironment.ContentRootPath, @"wwwroot\images\", gigInDb.ImageUrl);
                        if (System.IO.File.Exists(oldImage))
                        {
                            System.IO.File.Delete(oldImage);
                        }
                    }
                    gigInDb.ImageUrl = _uniqueImageName;
                }
            }
        }
Пример #3
0
        private IActionResult ReturnEntryToUser(GigsFormViewModel model)
        {
            model.Genres = _unitOfWork.Genres.GetGenres();
            model.EncryptionTechniques = GetEncryptionTechniques();

            return(View("GigForm", model));
        }
Пример #4
0
        public async Task <IActionResult> Update(GigsFormViewModel model)
        {
            if (!ModelState.IsValid)
            {
                model.Genres = await _unitOfWork.Genre.GetAllGenres();

                return(View("Edit", model));
            }

            var gig = await _unitOfWork.Gig.GetGigWithAttendees(model.Id);

            if (gig == null)
            {
                return(NotFound());
            }

            if (gig.ArtistId != _userManager.GetUserId(HttpContext.User))
            {
                return(Unauthorized());
            }

            if (gig.CantCancel())
            {
                return(BadRequest("Gig is cancelled or a past gig so you cant update"));
            }

            gig.Updated(gig.DateAndTime, gig.Venue);

            Mapper.Map <GigsFormViewModel, Models.Gig>(model, gig);

            await _unitOfWork.CompleteAsync();

            return(RedirectToAction("Mine"));
        }
Пример #5
0
        public IActionResult Create(GigsFormViewModel model)
        {
            var key       = _userManager.GetUserId(User);
            var signature = User.Identity.Name;

            // Check if the model state is valid with correct inputs from the user.
            if (!ModelState.IsValid)
            {
                return(ReturnEntryToUser(model));
            }

            // Check to see if a photo is selected by the user.
            if (model.Photo != null)
            {
                if (ProcessImageBeforeSaving(model, signature, key, out var actionResult))
                {
                    return(actionResult);
                }
            }

            CreateOrModifyAGig(model); // Create a gig object if adding a new gig or modify gig object if modifying a gig.
            _unitOfWork.Complete();    // Commit changes to the repository.

            // Redirect the user to the list of his/her upcoming gigs.
            return(View("MyUpcomingGigs", GetMyUpcomingModel(key)));
        }
Пример #6
0
        public async Task <IActionResult> Create(GigsFormViewModel model)
        {
            if (!ModelState.IsValid)
            {
                model.Genres = await _unitOfWork.Genre.GetAllGenres();

                return(View(model));
            }

            var userId = _userManager.GetUserId(User);

            var user = _unitOfWork.ApplicationUser.GetUserFollowers(userId);

            var gig = AutoMapper.Mapper.Map <GigsFormViewModel, Models.Gig>(model);

            gig.Artist = user;

            gig.Created();

            _unitOfWork.Gig.Add(gig);

            await _unitOfWork.CompleteAsync();

            return(RedirectToAction("Mine"));
        }
Пример #7
0
        public ActionResult Edit(int id)
        {
            var userId = User.Identity.GetUserId();

            var gig = _unitOfWork.Gigs.GetGig(id);

            if (gig == null)
            {
                return(HttpNotFound());
            }
            if (gig.ArtistId != userId)
            {
                return(new HttpUnauthorizedResult());
            }

            var viewModel = new GigsFormViewModel
            {
                Genres  = _unitOfWork.Genres.GetGenres(),
                Id      = gig.Id,
                Date    = gig.DateTime.ToString("d MMM yyyy"),
                Time    = gig.DateTime.ToString("HH:mm"),
                Venue   = gig.Venue,
                GenreId = gig.GenreId,
                Heading = "Edit a Gig"
            };


            return(View("GigForm", viewModel));
        }
Пример #8
0
        public ActionResult Update(GigsFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Genres = _unitOfWork.Genres.GetGenres();

                return(View("GigForm", viewModel));
            }


            var gig = _unitOfWork.Gigs.GetGigWithAttendees(viewModel.Id);

            if (gig == null)
            {
                return(HttpNotFound());
            }

            if (gig.ArtistId != User.Identity.GetUserId())
            {
                return(new HttpUnauthorizedResult());
            }


            gig.Modify(viewModel.GetDateTime(), viewModel.Venue, viewModel.GenreId);


            _unitOfWork.Complete();


            return(RedirectToAction("Mine", "Gigs"));
        }
Пример #9
0
        private IActionResult ReturnPrivacyWarning(GigsFormViewModel model)
        {
            ModelState.AddModelError("PrivacyWarning", "A copyright image detected, please replace image and try again.");
            model.Genres = _unitOfWork.Genres.GetGenres();
            model.EncryptionTechniques = GetEncryptionTechniques();

            return(View("GigForm", model));
        }
Пример #10
0
        public ActionResult Create()
        {
            var ViewModel = new GigsFormViewModel
            {
                Genres = _context.Genres.ToList()
            };

            return(View(ViewModel));
        }
Пример #11
0
        public async Task <IActionResult> Create()
        {
            var model = new GigsFormViewModel()
            {
                Genres = await _unitOfWork.Genre.GetAllGenres()
            };

            return(View(model));
        }
Пример #12
0
        public ActionResult Create()
        {
            var viewModel = new GigsFormViewModel
            {
                Genres  = _applicationDbContext.Genres.ToList(),
                Heading = "Create new Gig"
            };

            return(View("GigForm", viewModel));
        }
Пример #13
0
        public ActionResult Create()
        {
            var viewmodel = new GigsFormViewModel
            {
                Genres  = db.Genres.ToList(),
                Heading = "Add a Gig"
            };

            return(View("GigForm", viewmodel));
        }
Пример #14
0
        public IActionResult Create()
        {
            var model = new GigsFormViewModel
            {
                Genres = _unitOfWork.Genres.GetGenres(),
                EncryptionTechniques = GetEncryptionTechniques(), UserAction = New
            };

            return(View("GigForm", model));
        }
Пример #15
0
        public ActionResult Create()
        {
            var genres = _unitOfWork.Genres.GetGenres();

            var viewModel = new GigsFormViewModel
            {
                Genres  = genres,
                Heading = "Create a Gig"
            };


            return(View("GigForm", viewModel));
        }
Пример #16
0
        public ActionResult Update(GigsFormViewModel viewmodel)
        {
            if (!ModelState.IsValid)
            {
                viewmodel.Genres = db.Genres.ToList();
                return(View("GigForm", viewmodel));
            }
            var userId = User.Identity.GetUserId();
            var gig    = db.Gigs.Include(g => g.Attendances.Select(a => a.Attendee))
                         .Single(g => g.Id == viewmodel.Id && g.ArtistId == userId);

            gig.Modify(viewmodel.GetDateTime(), viewmodel.Venue, viewmodel.Genre);
            db.SaveChanges();
            return(RedirectToAction("Mine", "Gigs"));
        }
Пример #17
0
        public ActionResult Edit(int id)
        {
            var userId    = User.Identity.GetUserId();
            var gig       = _context.Gigs.Single(g => g.Id == id && g.ArtistId == userId);
            var viewModel = new GigsFormViewModel()
            {
                Genres  = _context.Genres.ToList(),
                Date    = gig.DateTime.ToString("d MMM yyyy"),
                Time    = gig.DateTime.ToString("HH:mm"),
                Genre   = gig.GenreId,
                Venue   = gig.Venue,
                Heading = "Edit a Gig",
                Id      = gig.Id
            };

            return(View("GigForm", viewModel));
        }
Пример #18
0
        public IActionResult Edit(string id)
        {
            var gigId = Convert.ToInt32(_gigIdDataProtector.Unprotect(id));
            var gig   = _unitOfWork.Gigs.FindGigById(gigId);

            //var model = new EditGigFormViewModel(gig)
            //{
            //    Genres = _unitOfWork.Genres.GetGenres()
            //};

            var model = new GigsFormViewModel()
            {
                Genres = _unitOfWork.Genres.GetGenres(), UserAction = Modify, EncryptionTechniques = GetEncryptionTechniques(), GigId = gig.Id,
                Venue  = gig.Venue, Genre = gig.GenreId, Date = gig.DateTime.ToShortDateString(), Time = gig.DateTime.ToShortTimeString()
            };

            return(View("GigForm", model));
        }
Пример #19
0
        public ActionResult Create(GigsFormViewModel viewmodel)
        {
            if (!ModelState.IsValid)
            {
                viewmodel.Genres = db.Genres.ToList();
                return(View("GigForm", viewmodel));
            }
            var gig = new Gig
            {
                ArtistId = User.Identity.GetUserId(),
                DateTime = viewmodel.GetDateTime(),
                GenreId  = viewmodel.Genre,
                Venue    = viewmodel.Venue,
            };

            db.Gigs.Add(gig);
            db.SaveChanges();
            return(RedirectToAction("Mine", "Gigs"));
        }
Пример #20
0
        public ActionResult Update(GigsFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Genres = _context.Genres.ToList();//viewmodel coming from Create view has it's Genres=null
                return(View("GigForm", viewModel));
            }

            var userId = User.Identity.GetUserId();
            var gig    = _context.Gigs.Single(g => g.Id == viewModel.Id && g.ArtistId == userId);

            gig.Venue    = viewModel.Venue;
            gig.DateTime = viewModel.GetDateTime();
            gig.GenreId  = viewModel.Genre;

            _context.SaveChanges();

            return(RedirectToAction("Mine", "Gigs"));
        }
Пример #21
0
        public ActionResult Create(GigsFormViewModel viewModel)
        {
            var artistId = User.Identity.GetUserId();
            var artist   = _context.Users.Single(u => u.Id == artistId);
            var genre    = _context.Genres.Single(g => g.Id == viewModel.Genre);

            var gig = new Gig
            {
                Artist   = artist,
                DateTime = DateTime.Parse(string.Format("{0} {1}", viewModel.Date, viewModel.Time)),
                Genre    = genre,
                Venue    = viewModel.Venue
            };

            _context.Gigs.Add(gig);
            _context.SaveChanges();

            return(RedirectToAction("Index", "Home"));
        }
Пример #22
0
        public ActionResult Edit(GigsFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Genres = _applicationDbContext.Genres.ToList();
                return(View("GigForm", viewModel));
            }

            var currentUserId = User.Identity.GetUserId();

            var gig = _applicationDbContext.Gigs
                      .Include(g => g.Attendences.Select(a => a.Attendee))
                      .Single(g => g.Id == viewModel.Id && g.ArtistId == currentUserId);

            gig.Notify(viewModel.GetDateTime(), viewModel.Vanue, viewModel.Genre);
            _applicationDbContext.SaveChanges();

            return(RedirectToAction("Mine", "Gigs"));
        }
Пример #23
0
        public ActionResult Create(GigsFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Genres = _context.Genres.ToList();//viewmodel coming from Create view has it's Genres=null
                return(View("GigForm", viewModel));
            }
            var gig = new Gig
            {
                ArtistId = User.Identity.GetUserId(),
                DateTime = viewModel.GetDateTime(),
                GenreId  = viewModel.Genre,
                Venue    = viewModel.Venue
            };

            _context.Gigs.Add(gig);
            _context.SaveChanges();

            return(RedirectToAction("Mine", "Gigs"));
        }
Пример #24
0
        public ActionResult Update(GigsFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                //Genres need to populate first
                viewModel.Genres = _context.Genre.ToList();
                return(View("GigForm", viewModel));
            }

            var userId = User.Identity.GetUserId();
            var gigs   = _context.Gigs.Single(g => g.Id == viewModel.Id && g.ArtistId == userId);

            gigs.Venue    = viewModel.Venue;
            gigs.DateTime = viewModel.GetDateTime();
            gigs.GenreId  = viewModel.Genre;

            _context.SaveChanges();


            return(RedirectToAction("Mine", "Gigs"));
        }
Пример #25
0
        public ActionResult Create(GigsFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                //Genres need to populate first
                viewModel.Genres = _context.Genre.ToList();
                return(View("GigForm", "Gigs"));
            }


            var gigs = new Gigs
            {
                ArtistId = User.Identity.GetUserId(),
                DateTime = viewModel.GetDateTime(),
                GenreId  = viewModel.Genre,
                Venue    = viewModel.Venue
            };

            _context.Gigs.Add(gigs);
            _context.SaveChanges();
            return(RedirectToAction("Mine", "Home"));
        }
Пример #26
0
        private string EncodeAndSaveImage(GigsFormViewModel model, Bitmap myImage, string signature, string key)
        {
            string uniqueImageName;
            string encodedSignature; // Container for encoded signature.

            switch (model.EncryptionType)
            {
            // If the user is not interested in signing the picture, save the picture.
            case "Select Encryption Type":
            {
                SaveImage(myImage, out uniqueImageName);
                break;
            }

            case "1":     // If user selected to sign his picture using Data Protection API
                encodedSignature = _imageValueDataProtector.Protect(signature);
                // Embed signature with 1 added to indicate Data Protection API Encryption was applied.
                var dataProtectionSignedImage = Steganography
                                                .EmbedTextToPicture($"1{encodedSignature}", myImage);
                SaveImage(dataProtectionSignedImage, out uniqueImageName);
                break;

            default:     // If the user selected to sign his picture using Triple DES Encryption.
            {
                encodedSignature = Security.TripleDes.Encrypt(signature, key);

                // Embed signature with 2 added to indicate Triple DES Encryption was applied.
                var tripleDesSignedImage = Steganography
                                           .EmbedTextToPicture($"2{encodedSignature}", myImage);
                SaveImage(tripleDesSignedImage, out uniqueImageName);
                break;
            }
            }

            return(uniqueImageName);
        }
Пример #27
0
        private bool ProcessImageBeforeSaving(GigsFormViewModel model, string signature, string key,
                                              out IActionResult actionResult)
        {
            using (var readStream = model.Photo.OpenReadStream())
            {
                var myImage = new Bitmap(Image.FromStream(readStream));
                var getEncodedTextInPicture =
                    Steganography.GetTextFromPicture(myImage); // Container for saving encoded text in picture

                // If the picture doesn't contains a text?
                if (string.IsNullOrEmpty(getEncodedTextInPicture))
                {
                    if (model.EncryptionType == NoEncryption) // The user chooses not to sign the picture.
                    {
                        SaveImage(myImage, out _uniqueImageName);
                    }
                    else
                    {
                        _uniqueImageName =
                            EncodeAndSaveImage(model, myImage, signature,
                                               key); // User chooses to sign the picture
                    }
                }
                else // The picture contains text.
                {
                    var    encryptionMethod = getEncodedTextInPicture.Substring(0, 1);
                    string decryptedSignature;

                    switch (encryptionMethod)
                    {
                    //Decrypt picture using Data Protection.
                    case DataProtection:
                    {
                        decryptedSignature = _imageValueDataProtector.Unprotect(getEncodedTextInPicture.Substring(1));
                        if (signature == decryptedSignature)
                        {
                            SaveImage(myImage, out _uniqueImageName);
                        }
                        else
                        {
                            actionResult = ReturnPrivacyWarning(model);
                            return(true);
                        }

                        break;
                    }

                    //Decrypt picture using Triple DES
                    case TripleDes:
                    {
                        decryptedSignature = Security.TripleDes.Decrypt(getEncodedTextInPicture.Substring(1), key);
                        if (signature == decryptedSignature)
                        {
                            SaveImage(myImage, out _uniqueImageName);
                        }
                        else
                        {
                            actionResult = ReturnPrivacyWarning(model);
                            return(true);
                        }

                        break;
                    }

                    default:
                    {
                        actionResult = ReturnPrivacyWarning(model);
                        return(true);
                    }
                    }
                }
            }

            actionResult = null;
            return(false);
        }