Ejemplo n.º 1
0
        public async Task <BikeViewModel> GetBike(Guid?id)
        {
            var bike = await _context.BicycleInventories.AsNoTracking()
                       .Include(x => x.BicycleType)
                       .FirstOrDefaultAsync(x => x.BikeId == id);

            if (bike != null)
            {
                var bikeDisplay = new BikeViewModel
                {
                    BikeId           = bike.BikeId,
                    Brand            = bike.Brand,
                    ModelNo          = bike.ModelNo,
                    SelectBikeTypeId = bike.BicycleType.BikeTypeId,
                    SelectedBikeType = bike.BicycleType.Type,
                    Status           = bike.Status,
                    BikeStatuses     = _statuses,
                    BikeTypes        = _bikeTypes
                };

                return(bikeDisplay);
            }

            return(null);
        }
Ejemplo n.º 2
0
        public IActionResult Checkout(long id, string customerName)
        {
            var bikeViewModel = new BikeViewModel
            {
                Bike = new Bike
                {
                    id           = id,
                    CustomerName = customerName,
                    DateModified = DateTime.Now,
                    CheckOutTime = DateTime.Now,
                    CheckInTime  = null
                }
            };

            if (id == 0)
            {
                bikeViewModel.Bike.id = _bikeService.GetLastId();
                _bikeService.AddBike(bikeViewModel.Bike);
            }
            else
            {
                _bikeService.UpdateBike(bikeViewModel.Bike);
            }

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 3
0
        //Main View
        public IActionResult Index()
        {
            BikeViewModel model = new BikeViewModel();

            model.Bikes = _context.bikes.ToList();
            return(View(model));
        }
Ejemplo n.º 4
0
        public async Task <IEnumerable <BikeViewModel> > GetBikes()
        {
            var bikes = new List <BicycleInventory>();

            bikes = await _context.BicycleInventories.AsNoTracking()
                    .Include(x => x.BicycleType)
                    .ToListAsync();

            if (bikes != null)
            {
                var bikesDisplay = new List <BikeViewModel>();
                foreach (var b in bikes)
                {
                    var bikeDisplay = new BikeViewModel()
                    {
                        BikeId           = b.BikeId,
                        Brand            = b.Brand,
                        ModelNo          = b.ModelNo,
                        SelectBikeTypeId = b.BicycleType.BikeTypeId,
                        SelectedBikeType = b.BicycleType.Type,
                        Status           = b.Status
                    };

                    bikesDisplay.Add(bikeDisplay);
                }

                return(bikesDisplay);
            }

            return(null);
        }
        public IActionResult Create(BikeViewModel vm)
        {
            _commandBuilder.Execute(new AddBikeCommandContext
            {
                Name     = vm.Name,
                Cost     = vm.Cost,
                HourCost = vm.HourCost
            });

            Bike currentBike = _queryBuilder
                               .For <Bike>()
                               .With(new BikeNameCriterion
            {
                Name = vm.Name
            });

            RentPoint currentRentPoint = _queryBuilder
                                         .For <RentPoint>()
                                         .With
                                             (new AdressCriterion
            {
                Adress = vm.RentPointAdress
            });

            _commandBuilder.Execute(new MoveBikeCommandContext
            {
                Bike      = currentBike,
                RentPoint = currentRentPoint
            });

            return(RedirectToAction("Edit", "RentPoint", new { adress = vm.RentPointAdress }));
        }
Ejemplo n.º 6
0
        public ActionResult GetView()
        {
            BikeListViewModel    bikeListViewModel = new BikeListViewModel();
            BikeBusinessLayer    bikeList          = new BikeBusinessLayer();
            List <Bike>          bikes             = bikeList.GetBikes();
            List <BikeViewModel> bikeViewModels    = new List <BikeViewModel>();

            foreach (Bike bike in bikes)
            {
                BikeViewModel bikeViewModel = new BikeViewModel();
                bikeViewModel.BikeNameAndModel = bike.BikeName + " " + bike.BikeModel;
                bikeViewModel.BikePrice        = bike.BikePrice.ToString("G");
                if (bike.BikePrice > 200000)
                {
                    bikeViewModel.BikeColor = "green";
                }
                else
                {
                    bikeViewModel.BikeColor = "red";
                }
                bikeViewModels.Add(bikeViewModel);
            }
            bikeListViewModel.Bikes = bikeViewModels;
            return(View("SampleView", bikeListViewModel));
        }
Ejemplo n.º 7
0
 public ActionResult SaveBike(Bike Bikes)
 {
     if (!ModelState.IsValid)
     {
         var viewModel = new BikeViewModel
         {
             Bikes           = Bikes,
             CubicCapacities = _Context.CubicCapacities.ToList()
         };
         return(View("BikeForm", viewModel));
     }
     if (Bikes.Id == 0)
     {
         _Context.Bikes.Add(Bikes);
     }
     else
     {
         var BikeInDB = _Context.Bikes.Single(b => b.Id == Bikes.Id);
         BikeInDB.Name            = Bikes.Name;
         BikeInDB.Model           = Bikes.Model;
         BikeInDB.CubicCapacityId = Bikes.CubicCapacityId;
         BikeInDB.DateOfPurchase  = Bikes.DateOfPurchase;
         BikeInDB.NumberOfBikes   = Bikes.NumberOfBikes;
     }
     _Context.SaveChanges();
     return(RedirectToAction("Index", "Bikes"));
 }
Ejemplo n.º 8
0
        public IActionResult Checkout(long id)
        {
            var bikeViewModel = new BikeViewModel();

            bikeViewModel.Bike = _bikeService.GetBike(id);

            return(View(bikeViewModel));
        }
        public IActionResult Create(string adress)
        {
            BikeViewModel bikeVm = new BikeViewModel
            {
                RentPointAdress = adress
            };

            return(View(bikeVm));
        }
Ejemplo n.º 10
0
        public async Task <ActionResult> Details(int id)
        {
            var model = new BikeViewModel
            {
                Bike = await repository.GetBike(id)
            };

            return(View(model));
        }
Ejemplo n.º 11
0
        public ActionResult Edit(int bikeid)
        {
            var BikeInfo = _Context.Bikes.SingleOrDefault(bike => bike.Id == bikeid);
            var BikeVM   = new BikeViewModel
            {
                Bikes           = BikeInfo,
                CubicCapacities = _Context.CubicCapacities.ToList()
            };

            return(View("BikeForm", BikeVM));
        }
Ejemplo n.º 12
0
 public BikeController(VroomDbContext db, IWebHostEnvironment hostEnvironment)
 {
     _db = db;
     this._hostEnvironment = hostEnvironment;
     BikeVM = new BikeViewModel()
     {
         Makes  = _db.Makes.ToList(),
         Models = _db.Models.ToList(),
         Bike   = new Models.Bike()
     };
 }
Ejemplo n.º 13
0
 public BikeController(VroomDbContext context, IWebHostEnvironment hostingEnvironment)
 {
     _db = context;
     _hostingEnvironment = hostingEnvironment;
     BikeViewModel       = new BikeViewModel()
     {
         Makes  = _db.Makes.ToList(),
         Models = _db.Models.ToList(),
         Bike   = new Models.Bike()
     };
 }
Ejemplo n.º 14
0
        public BikeController(BikeDbContext db)
        {
            _db = db;

            BikeVM = new BikeViewModel()
            {
                Makes  = _db.Makes.ToList(),
                Models = _db.Models.ToList(),
                Bike   = new Models.Bike()
            };
        }
Ejemplo n.º 15
0
        public BikeController(ApplicationDbContext db, IHostingEnvironment hostingEnvironment)
        {
            _db = db;
            _hostingEnvironment = hostingEnvironment;

            BikeVM = new BikeViewModel()
            {
                Category = _db.Categories,
                Bike     = new Bike()
            };
        }
Ejemplo n.º 16
0
 public BikeController(BroomDbContext context)
 {
     _context = context;
     //  _hosting = hosting; , HostingEnvironment hosting
     BikeVM = new BikeViewModel()
     {
         Makes   = _context.Makes.ToList(),
         BModels = _context.BModels.ToList(),
         Bike    = new Models.Bike()
     };
 }
Ejemplo n.º 17
0
 public BikeController(ApplicationDbContext db, IWebHostEnvironment webhostEnv)
 {
     _db         = db;
     _webhostEnv = webhostEnv;
     BikeVM      = new BikeViewModel()
     {
         Makes  = _db.Makes.ToList(),
         Models = _db.Models.ToList(),                  //changed to list of models
         Bike   = new Models.Bike()
     };
 }
Ejemplo n.º 18
0
        public ActionResult BikeForm()
        {
            var cubiccapsacity = _Context.CubicCapacities.ToList();
            var viewModel      = new BikeViewModel
            {
                Bikes           = new Bike(),
                CubicCapacities = cubiccapsacity
            };

            return(View(viewModel));
        }
Ejemplo n.º 19
0
 public BikeController(VroomDbContext db, HostingEnvironment hostingenvironment)
 {
     _db = db;
     _hostingenvironment = hostingenvironment;
     BikeVM = new BikeViewModel()
     {
         Makes  = _db.makes.ToList(),
         Models = _db.models.ToList(),
         Bike   = new Models.Bike()
     };
 }
Ejemplo n.º 20
0
 public BikeController(VroomDbContext _context, ILogger <BikeController> _logger, HostingEnvironment hostingEnvironment)
 {
     this._context = _context;
     this._logger  = _logger;
     BikeVM        = new BikeViewModel()
     {
         Makes   = _context.Make.ToList(),
         Models  = _context.Models.ToList(),
         BikeApp = new Models.Bike()
     };
     hostingEnvironment = hostingEnvironment;
 }
Ejemplo n.º 21
0
        public async Task <ActionResult> Edit(Bike bike)
        {
            TempData["message"] = string.Empty;
            string message;

            if (bike == null)
            {
                return(View(new BikeViewModel()));
            }

            bool succeeded;

            //add new bike
            if (bike.BikeID == 0)
            {
                succeeded = await repository.AddBike(bike);

                message = $"{bike.BikeID} has not been added";

                //Checking the response is successful or not
                if (succeeded)
                {
                    message = $"{bike.BikeID} has been added";
                }
            }
            else
            {
                //update existing bike
                succeeded = await repository.UpdateBike(bike);

                message = $"{bike.BikeID} has not been saved";
                //Checking the response is successful or not
                if (succeeded)
                {
                    message = $"{bike.BikeID} has been saved";
                }
            }
            TempData["message"] = message;

            if (succeeded)
            {
                return(RedirectToAction("Index"));
            }

            var model = new BikeViewModel
            {
                Bike = bike
            };

            return(View(model));
        }
Ejemplo n.º 22
0
        public async Task <IActionResult> Create([Bind(include: new string[] { "BikeId", "ModelNo", "Brand", "Status", "SelectedBikeType", "SelectBikeTypeId" })] BikeViewModel model)
        {
            if (ModelState.IsValid)
            {
                var response = await _bikeRepo.SaveBike(model);

                if (response)
                {
                    return(RedirectToAction("Index"));
                }
            }

            return(NoContent());
        }
Ejemplo n.º 23
0
        public async Task <ActionResult> Edit(int?id)
        {
            var model = new BikeViewModel();

            if (id == null)
            {
                model.Bike = new Bike();
                return(View(model));
            }

            model.Bike = await repository.GetBike(id);

            //model.Bikes
            return(View(model));
        }
Ejemplo n.º 24
0
        public void CreateBike(BikeViewModel model, string userId, byte[] imageData)
        {
            var res = _userManagerService.GetUserById(userId);

            _bikeRepository.Create(new Bike
            {
                Name        = model.Name,
                MaxSpeed    = model.MaxSpeed,
                TypeEngine  = model.TypeEngine,
                Power       = model.Power,
                Fuel        = model.Fuel,
                Description = model.Description,
                AccountId   = res.Result.Id,
                Price       = model.Price,
                BikeImg     = imageData
            });
            _commitProvider.Save();
        }
Ejemplo n.º 25
0
        public IActionResult Create(BikeViewModel bike)
        {
            var currentUserName = User.Identity.Name;
            var userId          = _userManagerService.GetUserByName(currentUserName);

            if (ModelState.IsValid)
            {
                if (bike.BikeImg != null)
                {
                    byte[] imageData = null;
                    using (var binaryReader = new BinaryReader(bike.BikeImg.OpenReadStream()))
                    {
                        imageData = binaryReader.ReadBytes((int)bike.BikeImg.Length);
                    }
                    _bikeService.CreateBike(bike, userId.Result.Id, imageData);
                    return(RedirectToAction("Index"));
                }
            }
            return(View(bike));
        }
Ejemplo n.º 26
0
        public async Task <bool> SaveBike(BikeViewModel model)
        {
            if (model != null)
            {
                var bike = new BicycleInventory
                {
                    BikeId      = Guid.NewGuid(),
                    ModelNo     = model.ModelNo,
                    Brand       = model.Brand,
                    Status      = model.Status,
                    BicycleType = await _context.BicycleTypes.FindAsync(model.SelectBikeTypeId)
                };

                _context.BicycleInventories.Add(bike);
                await _context.SaveChangesAsync();

                return(true);
            }

            return(false);
        }
Ejemplo n.º 27
0
        public ActionResult GetView()
        {
            Bike bike = new Bike();

            bike.BikeName  = "Pulsor";
            bike.BikeModel = "RS200";
            bike.BikePrice = 120000;

            BikeViewModel vmBike = new BikeViewModel();

            vmBike.BikeNameAndModel = bike.BikeName + " " + bike.BikeModel;
            vmBike.BikePrice        = bike.BikePrice.ToString("G");
            if (bike.BikePrice > 200000)
            {
                vmBike.BikeColor = "green";
            }
            else
            {
                vmBike.BikeColor = "red";
            }
            return(View("SampleView", vmBike));
        }
Ejemplo n.º 28
0
        public async Task <bool> UpdateBike(BikeViewModel model)
        {
            if (model != null)
            {
                var bike = new BicycleInventory
                {
                    BikeId      = model.BikeId,
                    ModelNo     = model.ModelNo,
                    Brand       = model.Brand,
                    Status      = model.Status,
                    BicycleType = await _context.BicycleTypes.FindAsync(model.SelectBikeTypeId)
                };

                var current = await _context.BicycleInventories.FindAsync(model.BikeId);

                _context.Entry(current).CurrentValues.SetValues(bike);
                await _context.SaveChangesAsync();

                return(true);
            }

            return(false);
        }
Ejemplo n.º 29
0
        public static IHtmlString ImageUpload(this HtmlHelper <BikeViewModel> htmlHelper, BikeViewModel viewModel)
        {
            var outerDiv = new TagBuilder("div");

            outerDiv.AddCssClass("pull-left upload-img-wrapper");
            var label = new TagBuilder("label");

            label.AddCssClass("upload-img");
            label.MergeAttribute("data-content", viewModel.ButtonText);

            var image = new TagBuilder("img");

            image.AddCssClass("img-responsive");
            image.MergeAttribute("src", viewModel.imageSource);
            image.MergeAttribute("width", "250");
            image.MergeAttribute("height", "250");

            var textbox = InputExtensions.TextBoxFor(htmlHelper, m => m.ImageName, new { type = "file", style = "display:none" });

            StringBuilder htmlBuilder = new StringBuilder();

            htmlBuilder.Append(label.ToString(TagRenderMode.StartTag));
            htmlBuilder.Append(image.ToString(TagRenderMode.Normal));
            htmlBuilder.Append(label.ToString(TagRenderMode.EndTag));
            htmlBuilder.Append(textbox.ToHtmlString());
            outerDiv.InnerHtml = htmlBuilder.ToString();
            var html = outerDiv.ToString(TagRenderMode.Normal);

            return(MvcHtmlString.Create(html));
        }
Ejemplo n.º 30
0
        public IActionResult Index(string name, int page = 1, SortState sortOrder = SortState.NameAsc)
        {
            var currentUserName = User.Identity.Name;
            var userId          = _userManagerService.GetUserByName(currentUserName);

            int pageSize = 10;

            var source = _bikeService.GetBikesOfCurrentProvider(userId.Result.Id);

            if (!String.IsNullOrEmpty(name))
            {
                source = source.Where(p => p.Name.Contains(name));
            }

            switch (sortOrder)
            {
            case SortState.NameDesc:
                source = source.OrderByDescending(s => s.Name);
                break;

            case SortState.MaxSpeedAsc:
                source = source.OrderBy(s => s.MaxSpeed);
                break;

            case SortState.MaxSpeedDesc:
                source = source.OrderByDescending(s => s.MaxSpeed);
                break;

            case SortState.TypeEngineAsc:
                source = source.OrderBy(s => s.TypeEngine);
                break;

            case SortState.TypeEngineDesc:
                source = source.OrderByDescending(s => s.TypeEngine);
                break;

            case SortState.PowerAsc:
                source = source.OrderBy(s => s.Power);
                break;

            case SortState.PowerDesc:
                source = source.OrderByDescending(s => s.Power);
                break;

            case SortState.FuelAsc:
                source = source.OrderBy(s => s.Fuel);
                break;

            case SortState.FuelDesc:
                source = source.OrderByDescending(s => s.Fuel);
                break;

            case SortState.PriceAsc:
                source = source.OrderBy(s => s.Price);
                break;

            case SortState.PriceDesc:
                source = source.OrderByDescending(s => s.Price);
                break;

            default:
                source = source.OrderBy(s => s.Name);
                break;
            }

            var count = source.Count();
            var items = source.Skip((page - 1) * pageSize).Take(pageSize).ToList();

            PageViewModel pageViewModel = new PageViewModel(count, page, pageSize);
            BikeViewModel viewModel     = new BikeViewModel
            {
                PageViewModel       = pageViewModel,
                BikeFilterViewModel = new BikeFilterViewModel(name),
                BikeSortViewModel   = new BikeSortViewModel(sortOrder),
                Bikes = items
            };

            return(View(viewModel));
        }