Пример #1
0
        public async Task <IActionResult> Login(Customer customer)
        {
            if (!string.IsNullOrEmpty(customer.Email) && !string.IsNullOrEmpty(customer.Password))
            {
                Customer lgncustomer = await _context.Customers.FirstOrDefaultAsync(c => c.Email == customer.Email);

                PasswordHasher <Customer> hasher = new PasswordHasher <Customer>(
                    new OptionsWrapper <PasswordHasherOptions>(
                        new PasswordHasherOptions()
                {
                    CompatibilityMode = PasswordHasherCompatibilityMode.IdentityV2
                })
                    );
                var result = hasher.VerifyHashedPassword(lgncustomer, lgncustomer.Password, customer.Password);
                if (lgncustomer != null && result == PasswordVerificationResult.Success)
                {
                    lgncustomer.Token = Guid.NewGuid().ToString();
                    await _context.SaveChangesAsync();

                    var option = new CookieOptions
                    {
                        Expires     = DateTime.Now.AddHours(1),
                        IsEssential = true
                    };
                    Response.Cookies.Append("Token", lgncustomer.Token, option);
                    return(RedirectToAction("Index", "Home"));
                }
            }
            return(View(customer));
        }
        public async Task <IActionResult> Create(Car car)
        {
            if (ModelState.IsValid)
            {
                if (car.PhotoFile != null && car.DetailPhotoFile != null && car.CartPhotoFile != null)
                {
                    try
                    {
                        FileManager manager = new FileManager(_webHostEnvironment);
                        car.Photo       = manager.Upload(car.PhotoFile);
                        car.CartPhoto   = manager.Upload(car.CartPhotoFile);
                        car.DetailPhoto = manager.Upload(car.DetailPhotoFile);
                    }
                    catch (Exception e)
                    {
                        ModelState.AddModelError("PhotoUplaod", e.Message);
                        throw;
                    }
                }
                _context.Add(car);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CarModelId"] = new SelectList(_context.CarModels, "Id", "Name", car.CarModelId);
            return(View(car));
        }
        public async Task <IActionResult> Create(Partner partner)
        {
            if (partner.PhotoFile != null)

            {
                try
                {
                    FileManager fileManager = new FileManager(_webHost);
                    partner.Photo = fileManager.Upload(partner.PhotoFile);
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("Photo", e.Message);
                    throw;
                }
            }
            if (ModelState.IsValid)
            {
                _context.Add(partner);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(partner));
        }
Пример #4
0
        public async Task <IActionResult> Create([Bind("Id,Icon,Title,Text")] WhatWeOffer whatWeOffer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(whatWeOffer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(whatWeOffer));
        }
        public async Task <IActionResult> Create([Bind("Id,Name,Status")] Coupon coupon)
        {
            if (ModelState.IsValid)
            {
                _context.Add(coupon);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(coupon));
        }
        public async Task <IActionResult> Create([Bind("Id,Question,Answer")] Faq faq)
        {
            if (ModelState.IsValid)
            {
                _context.Add(faq);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(faq));
        }
Пример #7
0
        public async Task <IActionResult> Create([Bind("Id,FacebookLink,TwitterLink,InstagramLink,GoogleLink,LinkedInLink,Phone,SupPhone,Email,SaleEmail,MainAdress,Adress,Logo,FooterLogo,FooterText,Payment")] Setting setting)
        {
            if (ModelState.IsValid)
            {
                _context.Add(setting);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(setting));
        }
        public async Task <IActionResult> Create([Bind("Id,Text,Name,Position,Company,Photo")] Testimonial testimonial)
        {
            if (ModelState.IsValid)
            {
                _context.Add(testimonial);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(testimonial));
        }
        public async Task <IActionResult> Create([Bind("Id,Icon,Name")] CarType carType)
        {
            if (ModelState.IsValid)
            {
                _context.Add(carType);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(carType));
        }
        public async Task <IActionResult> Create([Bind("Id,Name")] BlogCategory blogCategory)
        {
            if (ModelState.IsValid)
            {
                _context.Add(blogCategory);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(blogCategory));
        }
        public async Task <IActionResult> Create([Bind("Id,Photo,Title,Text")] SliderItem sliderItem)
        {
            if (ModelState.IsValid)
            {
                _context.Add(sliderItem);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(sliderItem));
        }
Пример #12
0
        public async Task <IActionResult> Create([Bind("Id,Title,Text")] OurVision ourVision)
        {
            if (ModelState.IsValid)
            {
                _context.Add(ourVision);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(ourVision));
        }
        public async Task <IActionResult> Create([Bind("Id,Photo,Name,Position,FacebookLink,TwitterLink,InstagramLink,LinkedInLink")] Team team)
        {
            if (ModelState.IsValid)
            {
                _context.Add(team);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(team));
        }
        public async Task <IActionResult> Create([Bind("Id,Name,CarBrandId")] CarModel carModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(carModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CarBrandId"] = new SelectList(_context.CarBrands, "Id", "Name", carModel.CarBrandId);
            return(View(carModel));
        }
        public async Task <IActionResult> Create([Bind("Id,Name,BlogId")] Tag tag)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tag);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BlogId"] = new SelectList(_context.Blogs, "Id", "InfoText", tag.BlogId);
            return(View(tag));
        }
        public async Task <IActionResult> Create([Bind("Id,Name,Price,OrderItemId")] CarExtraService carExtraService)
        {
            if (ModelState.IsValid)
            {
                _context.Add(carExtraService);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["OrderItemId"] = new SelectList(_context.OrderItems, "Id", "Id", carExtraService.OrderItemId);
            return(View(carExtraService));
        }
        public async Task <IActionResult> Checkout(int?id)
        {
            if (id == null)
            {
                var token = Request.Cookies["Token"];

                if (token == null)
                {
                    return(RedirectToAction("Login", "Customers"));
                }
                Customer customer = await _context.Customers.FirstOrDefaultAsync(c => c.Token == token);

                Order model = await _context.Orders.Include("OrderItems").Include("OrderItems.Car").Include("OrderItems.Car.Model").Where(a => a.Status == true).FirstOrDefaultAsync(o => o.CustomerId == customer.Id);

                if (model == null)
                {
                    return(RedirectToAction("List", "Cars"));
                }
                decimal total = 0;
                var     days  = (model.DropDate - model.PickupDate).Days;
                foreach (var item in model.OrderItems)
                {
                    total = item.Car.DailyPrice * days;
                }
                model.Total = total;
                await _context.SaveChangesAsync();

                return(View(model));
            }
            Order order = await _context.Orders.Include("OrderItems").Include("OrderItems.Car").FirstOrDefaultAsync(o => o.CustomerId == id);

            return(View(order));
        }
        public async Task <IActionResult> Create(Order order, int carid)
        {
            var token = Request.Cookies["Token"];

            if (token == null)
            {
                ViewData["Requires Login"] = "******";
                return(RedirectToAction("Login", "Customers"));
            }
            Customer customer = await _context.Customers.FirstOrDefaultAsync(c => c.Token == token);

            if (customer != null)
            {
                if (!string.IsNullOrEmpty(order.PickupLocation) && !string.IsNullOrEmpty(order.DropLocation))
                {
                    Order neworder = new Order
                    {
                        CustomerId     = customer.Id,
                        Total          = 0,
                        PickupLocation = order.PickupLocation,
                        PickupDate     = order.PickupDate,
                        DropLocation   = order.DropLocation,
                        DropDate       = order.DropDate,
                        Status         = true
                    };
                    await _context.Orders.AddAsync(neworder);

                    await _context.SaveChangesAsync();

                    OrderItem orderItem = new OrderItem
                    {
                        CarId   = carid,
                        OrderId = neworder.Id,
                        Status  = true
                    };
                    Car car = await _context.Cars.FirstOrDefaultAsync(c => c.Id == carid);

                    car.Status = false;
                    await _context.OrderItems.AddAsync(orderItem);

                    await _context.SaveChangesAsync();
                }
                ;
                return(RedirectToAction("Detail", "Cars", new { id = carid }));
            }
            return(RedirectToAction("Checkout", "Pages", new { id = customer.Id }));
        }
Пример #19
0
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            var order = await _context.Orders.FindAsync(id);

            _context.Orders.Remove(order);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> Create([Bind("Id,GalleryId,Photo,PhotoSm,PhotoSmFile,PhotoFile")] GalleryItem galleryItem)
        {
            if (galleryItem.PhotoFile != null)
            {
                try
                {
                    FileManager fileManager = new FileManager(_webHostEnvironment);
                    galleryItem.Photo   = fileManager.Upload(galleryItem.PhotoFile);
                    galleryItem.PhotoSm = fileManager.Upload(galleryItem.PhotoSmFile);
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("PhotoFile", e.Message);
                }
            }
            if (ModelState.IsValid)
            {
                _context.Add(galleryItem);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(galleryItem));
        }