示例#1
0
        // GET: Carts
        public ActionResult Index()
        {
            var logs       = db.LogRecords.Where(l => l.RecordType == Utilities.RecordType.New && l.Guid == typeof(Cart).GUID).OrderByDescending(l => l.DateTime).Take(15);
            var list       = logs.Select(l => db.Carts.FirstOrDefault(c => c.Id == l.RecordId));
            var cartSearch = Session["CartSearch"] ?? new CartSearch <int>()
            {
                SearchType = nameof(Cart.SearchOptions.None)
            };
            CartSearch <int>      iSearch  = cartSearch as CartSearch <int>;
            CartSearch <string>   sSearch  = cartSearch as CartSearch <string>;
            CartSearch <DateTime> dtSearch = cartSearch as CartSearch <DateTime>;
            IEnumerable <Cart>    carts    = null;

            if (iSearch != null)
            {
                carts = ProcessSearch(iSearch);
            }
            else if (sSearch != null)
            {
                carts = ProcessSearch(sSearch);
            }
            else if (dtSearch != null)
            {
                carts = ProcessSearch(dtSearch);
            }
            CartIndexVM ciVM = new CartIndexVM();

            ciVM.Carts         = carts;
            ciVM.SearchOptions = new SelectList(Cart.SearchOptionNames, "Key", "Value");
            return(View(ciVM));
        }
示例#2
0
 public static void ClearCart()
 {
     cart            = new CartIndexVM();
     cart.Jela       = new List <CartRow>();
     cart.Pica       = new List <CartRow>();
     cart.TotalPrice = 0;
     //label4.Text = "0";
 }
示例#3
0
 public void ClearCart()
 {
     cart            = new CartIndexVM();
     cart.Jela       = new List <CartRow>();
     cart.Pica       = new List <CartRow>();
     cart.TotalPrice = 0;
     label4.Text     = "0";
     SetBtnOdaberiStoVisibility();
 }
示例#4
0
        // Android-specific code
#endif
        protected override void OnStart()
        {
            var cart = new CartIndexVM();

            cart.Jela                  = new List <CartRow>();
            cart.Pica                  = new List <CartRow>();
            cart.TotalPrice            = 0.00;
            ApplicationProperties.cart = cart;
            // Handle when your app starts
        }
示例#5
0
        //public ViewResult Checkout(int? userId)
        //{
        //    User user = db.Users.FirstOrDefault(u => u.UserId == userId);
        //    return View(user);
        //}

        // GET: Cart/Checkout
        public ViewResult Checkout(int?userId, ShoppingCart cart)
        {
            User user = db.Users.FirstOrDefault(u => u.UserId == userId);

            CartIndexVM cartIndexVM = new CartIndexVM
            {
                Cart      = cart,
                ReturnUrl = null,
                User      = db.Users.Where(u => u.UserId == userId).FirstOrDefault()
            };

            return(View(cartIndexVM));
        }
示例#6
0
        public void Can_View_Cart_Contents()
        {
            // Arrange - create a Cart
            Cart cart = new Cart();
            // Arrange - create the controller
            CartController target = new CartController(null, null);
            // Act - call the Index action method
            CartIndexVM result = (CartIndexVM)target.Index(cart, "myUrl").ViewData.Model;

            // Assert
            Assert.AreSame(result.Cart, cart);
            Assert.AreEqual(result.ReturnUrl, "myUrl");
        }
示例#7
0
        public ActionResult Register(CartIndexVM model)
        {
            User user = new User();

            if (ModelState.IsValid)
            {
                // Mapping ViewModel => entity
                //user.UserName = model.UserName;
                //user.UserPassword = model.UserPassword;
                //user.UserName = model.UserName;
                //user.UserEmail = model.UserEmail;
                //user.Birthday = model.Birthday;
                //user.UserLastName = model.UserLastName;
                //user.UserFirstName = model.UserFirstName;
                //user.UserAddress = model.UserAddress;
                //user.UserPost = model.UserPost;
                //user.UserGemeente = model.UserGemeente;
                //user.UserPhone = model.UserPhone;
                // Aanmaak Hash-paswoord en Role als klant:
                //user.PasswordHash = FormsAuthentication.HashPasswordForStoringInConfigFile(user.UserPassword, "md5");
                //Role userRole = db.Roles.FirstOrDefault(r => r.RoleName == "Klant");
                //user.Roles.Add(userRole);
                //db.Users.Add(user);
                //db.SaveChanges();

                // Aanmaak van de email
                //string body = "<p>Beste {0},</br></p><p>Bedankt voor uw registratieaanvraag! U kan meteen aan de slag.</p><p><u>Gegevens:</u></br></p><p>Naam: {0} {1}.</p><p>TEL / GSM: {2} </p><p>Email: {3}.</p><p>Adres: {4}</p><p></br>Met vriendelijke groeten,</br></p><p>Uw webmaster</p>";
                //var message = new MailMessage();
                //message.To.Add(new MailAddress("*****@*****.**"));
                //message.To.Add(new MailAddress("*****@*****.**"));
                //message.To.Add(new MailAddress("*****@*****.**"));
                //message.Subject = string.Format("Nieuwe registratie-aanvraag van website Ivo Bytes");
                //message.Body = string.Format(body, user.UserFirstName, user.UserLastName, user.UserPhone, user.UserEmail, user.UserAddress);
                //message.IsBodyHtml = true;

                // Versturen van de mail via smtpClient => configuratie in web.config
                //SmtpClient smtp = new SmtpClient();
                //smtp.Send(message);

                // Gebruik van Tempdata om Indexpagina te voorzien met een melding wanneer mail gestuurd werd.
                //TempData["Success"] = "Bedankt voor uw registratie! We nemen snel contact met u op.";

                return(RedirectToAction("Index", "Home"));
            }
            // Modelstate not valid? See errors:
            var errors = ModelState.Values.SelectMany(v => v.Errors);

            return(View());
        }
示例#8
0
 public bool CartExists()
 {
     if (cart != null)
     {
         return(true);
     }
     else
     {
         cart            = new CartIndexVM();
         cart.Jela       = new List <CartRow>();
         cart.Pica       = new List <CartRow>();
         cart.TotalPrice = 0;
         return(false);
     }
 }
示例#9
0
        private void odabirStola(object sender, EventArgs e)
        {
            if (sender != null && sender is Button btn)
            {
                if (int.TryParse(btn.Text, out var brojStola))
                {
                    var odabraniSto = stolovi.FirstOrDefault(x => x.RedniBrojStola == brojStola);
                    if (DatumRezervacije != DateTime.MinValue) // uvijek razlicito
                    {
                        if (odabraniSto.IsSlobodan)
                        {
                            btn.BackColor = zauzetiStoColor;
                            postCheckout.AddBearerToken(((Form1)this.ParentForm).VerifikovaniKorisnik.Token);
                            CartIndexVM cartItems = ((Form1)this.ParentForm).GetCartForCheckout();
                            var         response2 = postCheckout.PostWithParametar(brojStola, cartItems);
                            if (response2.IsSuccessStatusCode)
                            {
                                var response = postRezervisiSto.PostWithParametar(brojStola, DatumRezervacije.ToString("o"));

                                MessageBox.Show("Uspjesno obavljena rezervacija.");
                            }
                            else
                            {
                                MessageBox.Show("Neuspjesno obavljena rezervacija, morate dodati artikle u korpu.");
                            }
                        }
                        else
                        {
                            var response = postIzbrisiRezervaciju.PostResponse(odabraniSto.RezervacijaId);
                            if (response.IsSuccessStatusCode)
                            {
                                btn.BackColor = Color.Transparent;
                                MessageBox.Show("Uspjesno izbrisana rezervacija");
                            }
                        }
                        odabraniSto.IsSlobodan = !odabraniSto.IsSlobodan;
                    }
                }

                BindControlsAndData();
            }
        }
示例#10
0
        public VerifikovanKorisnikVM VerifikovaniKorisnik; // za konstruktora


        public Form1(VerifikovanKorisnikVM korisnik)
        {
            VerifikovaniKorisnik = korisnik;
            controlsHistory      = new LinkedList <Control>();
            InitializeComponent();
            string[] tipKorisnika = { "Admin", "Menadzer", "Klijent", "Konobar", "Kuhar", "Sanker" };
            korisnikLabel.Text = tipKorisnika[(int)korisnik.TipKorisnika];
            SetupLayoutForUser();
            cart              = new CartIndexVM();
            cart.Jela         = new List <CartRow>();
            cart.Pica         = new List <CartRow>();
            cart.TotalPrice   = 0.00;
            this.AutoValidate = AutoValidate.Disable;
            //cardsPanel1.SendToBack();
            //firstCustomControl2.SendToBack();
            btnHome_Click(btnHome, null);

            //dodajProizvod.Visible = false;
            //vScrollBar1.Visible = false;
            //activeControl = firstCustomControl1.Name;
        }
示例#11
0
        public IHttpActionResult Checkout(int?stoId, [FromBody] CartIndexVM cart)
        {
            var korisnik = JwtAuthenticationAttribute.GetKorisnik(this.Request.Headers.Authorization);

            if (cart.Jela.Count == 0 && cart.Pica.Count == 0)
            {
                return(BadRequest());
            }

            if (korisnik.TipKorisnika != TipKorisnika.Konobar && korisnik.TipKorisnika != TipKorisnika.Klijent)
            {
                return(NotFound());
            }

            Narudzba narudzba     = new Narudzba();
            int      zaposlenikId = 0;
            int      klijentId    = 0;

            if (stoId != null)
            {
                narudzba.StoId = (int)stoId;
            }
            ctx.Narudzbe.Add(narudzba);
            ctx.SaveChanges();


            if (korisnik.TipKorisnika == TipKorisnika.Konobar)
            {
                zaposlenikId          = korisnik.Id;
                narudzba.ZaposlenikId = zaposlenikId;
                narudzba.Sifra        = "Z" + zaposlenikId + "N" + narudzba.Id;
            }
            if (korisnik.TipKorisnika == TipKorisnika.Klijent)
            {
                klijentId          = korisnik.Id;
                narudzba.KlijentId = klijentId;
                narudzba.Sifra     = "K" + klijentId + "N" + narudzba.Id;
            }

            narudzba.StatusJela = statusNarudzbe.U_Pripremi;
            narudzba.StatusPica = statusNarudzbe.U_Pripremi;
            ctx.Narudzbe.AddOrUpdate(narudzba);
            ctx.SaveChanges();



            List <NarudzbaStavke> narudzbaStavke = new List <NarudzbaStavke>();
            double racunTotal = 0;

            if (cart.Jela.Count != 0)
            {
                narudzbaStavke = cart.Jela.Select(x => new NarudzbaStavke
                {
                    NarudzbaId = narudzba.Id,
                    JeloId     = x.Id,
                    Kolicina   = x.Kolicina
                }).ToList();

                foreach (var x in cart.Jela)
                {
                    racunTotal += ctx.Jelo.Where(y => y.Id == x.Id).SingleOrDefault().Cijena *x.Kolicina;
                    List <JelaStavke> proizvodi = ctx.JelaStavke.Where(y => y.JeloId == x.Id).ToList();
                    foreach (var stavka in proizvodi)
                    {
                        ctx.Proizvodi.Where(y => y.Id == stavka.ProizvodId).SingleOrDefault().Kolicina -= stavka.Kolicina * x.Kolicina;
                        ctx.SaveChanges();
                    }
                }
            }

            if (cart.Pica.Count != 0)
            {
                narudzbaStavke.AddRange(cart.Pica.Select(x => new NarudzbaStavke
                {
                    NarudzbaId = narudzba.Id,
                    ProizvodId = x.Id,
                    Kolicina   = x.Kolicina
                }).ToList());
                foreach (var x in cart.Pica)
                {
                    racunTotal += ctx.Proizvodi.Where(y => y.Id == x.Id).SingleOrDefault().Cijena *x.Kolicina;
                    ctx.Proizvodi.Where(y => y.Id == x.Id).SingleOrDefault().Kolicina -= x.Kolicina;
                    ctx.SaveChanges();
                }
            }
            ctx.NarudzbaStavke.AddRange(narudzbaStavke);
            ctx.SaveChanges();

            NarudzbaRacun racun = new NarudzbaRacun();

            racun.DatumIzdavanja = DateTime.Now;
            racun.Sifra          = narudzba.Sifra;

            if (korisnik.TipKorisnika == TipKorisnika.Konobar)
            {
                racun.ZaposlenikId = korisnik.Id;
            }
            if (korisnik.TipKorisnika == TipKorisnika.Klijent)
            {
                racun.KlijentId = korisnik.Id;
            }

            racun.Iznos = racunTotal;
            racun.Id    = narudzba.Id;
            ctx.Racuni.Add(racun);
            ctx.SaveChanges();

            return(Ok());
        }