Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(EditPackageViewModel vm)
        {
            if (ModelState.IsValid)
            {
                ApplicationUser currentUser = await _userManagerService.FindByNameAsync(User.Identity.Name);

                Provider currentProvider = _providerRepo.GetSingle(p => p.UserId == currentUser.Id);

                Package editablePackage = _packageRepo.GetSingle(p => p.PackageId == vm.PackageId);

                /*
                 * Package editedPackage = new Package
                 * {
                 *  PackageId = vm.PackageId,
                 *  ProviderId = vm.ProviderId,
                 *  Name = vm.Name,
                 *  ThumbnailUrl = vm.ThumbnailUrl,
                 *  Location = vm.Location,
                 *  Description = vm.Description,
                 *  Price = vm.Price,
                 *  IsActive = vm.IsActive
                 * };
                 */
                string thumbnailUrl = "";

                if (vm.ThumbnailUrl != null && vm.ThumbnailUrl != "")
                {
                    thumbnailUrl = $@"\images\" + currentProvider.UserId + "\\" + vm.ThumbnailUrl;
                }

                editablePackage.PackageId    = vm.PackageId;
                editablePackage.ProviderId   = vm.ProviderId;
                editablePackage.Name         = vm.Name;
                editablePackage.ThumbnailUrl = thumbnailUrl;
                editablePackage.Location     = vm.Location;
                editablePackage.Description  = vm.Description;
                editablePackage.Price        = vm.Price;
                editablePackage.IsActive     = vm.IsActive;


                _packageRepo.Update(editablePackage);

                return(RedirectToAction("Index"));
            }
            return(View(vm));
        }
Ejemplo n.º 2
0
        public ViewResult Edit(int id)
        {
            ViewData["Measures"] = _databaseContext.Measure.ToList();

            var ses = _databaseContext.Package.Include(t => t.Measure)
                      .FirstOrDefault(p => p.PackageId == id);

            ViewData["Success"] = TempData["Success"];

            var model = new EditPackageViewModel
            {
                IndividualSize = ses.IndividualSize,
                PackageId      = ses.PackageId,
                PackageType    = ses.PackageType,
                Quantity       = ses.Quantity
            };

            return(View(model));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Edit(int id)
        {
            ApplicationUser currentUser = await _userManagerService.FindByNameAsync(User.Identity.Name);

            Provider currentProvider = _providerRepo.GetSingle(p => p.UserId == currentUser.Id);

            Package editablePackage = _packageRepo.GetSingle(p => p.PackageId == id);

            //Look up images on the server
            IEnumerable <string> imagePaths        = new List <string>();
            List <string>        imageNames        = new List <string>();
            List <string>        imageCorrectPaths = new List <string>();

            string folderPath = _hostingEnv.WebRootPath + $@"\images\" + currentProvider.UserId;

            if (Directory.Exists(folderPath))
            {
                imagePaths = Directory.GetFiles(folderPath);

                foreach (var item in imagePaths)
                {
                    int    endPos    = item.LastIndexOf("\\");
                    string newString = item.Substring(endPos);
                    imageCorrectPaths.Add($@"\images\" + currentProvider.UserId + newString);
                }
            }

            EditPackageViewModel vm = new EditPackageViewModel
            {
                PackageId    = id,
                ProviderId   = editablePackage.ProviderId,
                Name         = editablePackage.Name,
                ThumbnailUrl = editablePackage.ThumbnailUrl,
                Location     = editablePackage.Location,
                Description  = editablePackage.Description,
                Price        = editablePackage.Price,
                IsActive     = editablePackage.IsActive,
                ImageNames   = imageCorrectPaths //imageNames
            };

            return(View(vm));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> EditPackage(string packageId)
        {
            await GetLoggedInUser();

            var tourPackage = await _tourPackageService.GetPackageWithRelatedSpotsAsync(new Guid(packageId));

            var model = new EditPackageViewModel()
            {
                packageId    = tourPackage.Id,
                PackageCode  = tourPackage.PackageCode,
                Division     = tourPackage.Division,
                Days         = tourPackage.Days,
                Price        = tourPackage.Price,
                Availability = tourPackage.Availability,
                Discount     = tourPackage.Discount,
                Spots        = (from s in tourPackage.Spots
                                select s.Name).ToList()
            };

            return(View(model));
        }
Ejemplo n.º 5
0
        public IActionResult Update(int id, EditPackageViewModel model)
        {
            ViewData["Measures"] = _databaseContext.Measure.ToList();
            if (id != 0)
            {
                model.PackageId = id;
            }

            if (ModelState.IsValid)
            {
                var ses = _databaseContext.Package.Include(p => p.Measure).FirstOrDefault(m => m.PackageId == id);
                ses.Measure = _databaseContext.Measure.ToList().First(c => c.MeasureId == model.MeasureId);

                ses.PackageType    = model.PackageType;
                ses.IndividualSize = model.IndividualSize;
                ses.Quantity       = model.Quantity;
                ses.MeasureName    = ses.Measure.MeasureName;

                var x = _databaseContext.Package.Where(g => (g.PackageType == ses.PackageType && g.IndividualSize == ses.IndividualSize && g.Quantity == ses.Quantity && g.MeasureName == ses.MeasureName && g.PackageId != id)).ToList();
                if (x.Count > 0)
                {
                    TempData[Constants.Message]       = $"Takvo pakiranje već postoji.\n";
                    TempData[Constants.ErrorOccurred] = true;
                    return(View("Edit", model));
                }

                TempData["Success"] = true;
                _databaseContext.SaveChanges();

                TempData[Constants.Message]       = $"Pakiranje je promijenjeno";
                TempData[Constants.ErrorOccurred] = false;
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                ViewData["Measures"] = _databaseContext.Measure.ToList();
                return(View("Edit", model));
            }
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> EditPackage(EditPackageViewModel model)
        {
            var tourPackage = await _tourPackageService.GetPackageWithRelatedSpotsAsync(model.packageId);

            await GetLoggedInUser();

            if (ModelState.IsValid)
            {
                // delete all spots
                foreach (var spot in tourPackage.Spots.ToList())
                {
                    await _tourPackageService.DeleteSpotAsync(spot);
                }

                // Rebuild the package spots from model
                tourPackage.Division     = model.Division;
                tourPackage.Days         = model.Days;
                tourPackage.Price        = model.Price;
                tourPackage.Availability = model.Availability;
                tourPackage.Discount     = model.Discount;
                foreach (var spot in model.Spots)
                {
                    var newSpot = new Spot()
                    {
                        Name          = spot,
                        TourPackageId = tourPackage.Id
                    };

                    await _tourPackageService.AddSpot(newSpot);
                }

                await _tourPackageService.EditAsync(tourPackage);

                return(RedirectToAction("CompanyPublicView", "Company", new { companyId = tourPackage.CompanyId }));
            }

            return(View(model));
        }