public IActionResult ExperienceEdit(int id)
        {
            var experience = _ExperienceService.GetExperienceWithCategoriesById(id);

            if (experience != null)
            {
                var allCategories          = _CategoryService.GetAll().ToList();
                var categoriesOfExperience = experience.ExperienceCategoryJunctions.Select(s => s.Category).ToList();
                var locationId             = experience.LocationId;

                var model = new ExperienceCreateUpdateModel()
                {
                    ExperienceId            = experience.ExperienceId,
                    Name                    = experience.Name,
                    Title                   = experience.Title,
                    Author                  = experience.Author,
                    Body                    = experience.Body,
                    ImageUrl                = experience.ImageUrl,
                    AllCategories           = allCategories,
                    AllLocations            = _LocationService.GetAll(),
                    CategoriesOfThisListing = categoriesOfExperience,
                    LocationID              = locationId
                };
                return(View(model));
            }
            return(NotFound());
        }
        public IActionResult ExperienceCreate(int?id)
        {
            var allCategories = _CategoryService.GetAll().ToList();

            var model = new ExperienceCreateUpdateModel()
            {
                AllCategories        = allCategories,
                AllLocations         = _LocationService.GetAll(),
                LocationOfExperience = (id == null) ? new Location() : _LocationService.GetById((int)id)
            };

            return(View(model));
        }
        public async Task <IActionResult> ExperienceCreate(ExperienceCreateUpdateModel model, int[] selectedCategoryIds, IFormFile file)
        {
            if (ModelState.IsValid)
            {
                var user = await _UserManager.FindByNameAsync(User.Identity.Name);

                var entity = new Experience()
                {
                    Name            = model.Name,
                    Title           = model.Title,
                    Author          = model.Author,
                    Body            = model.Body,
                    LocationId      = model.LocationOfExperience.LocationId,
                    BeenThereUserId = user.Id,
                    ImageUrl        = "defaultExperiencePic.jpg"
                };
                var locationOfExperience = _LocationService.GetById(model.LocationOfExperience.LocationId);

                await UpdateCountryCodeList(user.Id.ToString(), locationOfExperience.CountryCode, null);

                if (file != null)
                {
                    var extention  = Path.GetExtension(file.FileName);
                    var randomName = string.Format($"{Guid.NewGuid()}{extention}");
                    entity.ImageUrl = randomName;
                    var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot//img", randomName);

                    using (var stream = new FileStream(path, FileMode.Create))
                    {
                        await file.CopyToAsync(stream);
                    }
                }


                _ExperienceService.Create(entity);

                _ExperienceService.AddCategoriesToExperience(entity, selectedCategoryIds);

                if (model.LocationOfExperience.LocationId > 0)
                {
                    var locationToBeEdited = _LocationService.GetById(model.LocationOfExperience.LocationId);

                    _LocationService.AttachCategoriesToLocation(locationToBeEdited, selectedCategoryIds);
                }

                return(Redirect("/social/experiencedetails/" + entity.ExperienceId));
            }
            return(View(model));
        }
        public async Task <IActionResult> ExperienceEdit(ExperienceCreateUpdateModel experienceModel, int[] selectedCategoryIds, IFormFile file)
        {
            if (ModelState.IsValid)
            {
                var experienceToBeEdited = _ExperienceService.GetById(experienceModel.ExperienceId);

                if (experienceToBeEdited != null)
                {
                    experienceToBeEdited.Name  = experienceModel.Name;
                    experienceToBeEdited.Title = experienceModel.Title;
                    experienceToBeEdited.Body  = experienceModel.Body;
                    if (experienceModel.LocationChoiceId != null)
                    {
                        experienceToBeEdited.LocationId = experienceModel.LocationChoiceId;
                    }


                    if (file != null)
                    {
                        var extention  = Path.GetExtension(file.FileName);
                        var randomName = string.Format($"{Guid.NewGuid()}{extention}");
                        experienceToBeEdited.ImageUrl = randomName;
                        var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot//img", randomName);

                        using (var stream = new FileStream(path, FileMode.Create))
                        {
                            await file.CopyToAsync(stream);
                        }
                    }



                    _ExperienceService.Update(experienceToBeEdited, selectedCategoryIds);

                    return(Redirect("/social/experiencedetails/" + experienceModel.ExperienceId));
                }
                return(NotFound());
            }
            experienceModel.ExperienceEditModelStateInvalid = true;

            return(View("experiencedetails", experienceModel));
        }
        public async Task <IActionResult> ExperienceDetails(int id)
        {
            var experience = _ExperienceService.GetExperienceWithCategoriesById(id);

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

            var categoriesOfExperience = experience.ExperienceCategoryJunctions.Select(s => s.Category).ToList();
            var locationOfExperience   = new Location();
            var commentsOfExperience   = _CommentService.GetAll().Where(i => i.ExperienceId == id).OrderByDescending(x => x.CommentId).ToList();
            var user = await _UserManager.FindByNameAsync(experience.Author);

            var model = new ExperienceCreateUpdateModel()
            {
                ExperienceId            = experience.ExperienceId,
                Name                    = experience.Name,
                Title                   = experience.Title,
                Author                  = experience.Author,
                Body                    = experience.Body,
                ImageUrl                = experience.ImageUrl,
                CategoriesOfThisListing = categoriesOfExperience,
                CommentsOfThisListing   = commentsOfExperience,
                AllCategories           = _CategoryService.GetAll(),
                CreationDate            = experience.DateOfCreation,
                AuthorProfilePicUrl     = user.ProfilePicUrl
            };

            if (experience.LocationId != null)
            {
                model.LocationOfExperience = locationOfExperience = _LocationService.GetById((int)experience.LocationId);
            }
            ;


            return(View(model));
        }