public IHttpActionResult PutGiaTien(int id, GiaTien giaTien)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != giaTien.Id)
            {
                return(BadRequest());
            }

            unitOfWork.GiaTienRepository.Update(giaTien);

            try
            {
                unitOfWork.Save();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!GiaTienExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        private void InputMaVach_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                switch (((TextBox)sender).Name)
                {
                case "MaVach":
                    int index = IsBarcodeExist(MaVach.Text);
                    if (index > 0)
                    {
                        TenSanPham.Text = DataExcel.Rows[index][1].ToString();
                        GiaTien.Text    = DataExcel.Rows[index][2].ToString();
                    }
                    else
                    {
                        TenSanPham.Text = "";
                        GiaTien.Text    = "";
                    }

                    TenSanPham.Focus();
                    TenSanPham.SelectAll();
                    break;

                case "TenSanPham":
                    GiaTien.Focus();
                    GiaTien.SelectAll();
                    break;

                case "GiaTien":
                    SaveBarcode();
                    break;
                }
            }
        }
        public IHttpActionResult GetGiaTien(int id)
        {
            GiaTien giaTien = unitOfWork.GiaTienRepository.GetByID(id);

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

            return(Ok(giaTien));
        }
        public IHttpActionResult PostGiaTien(GiaTien giaTien)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            unitOfWork.GiaTienRepository.Insert(giaTien);
            unitOfWork.Save();

            return(CreatedAtRoute("DefaultApi", new { id = giaTien.Id }, giaTien));
        }
Esempio n. 5
0
        public IHttpActionResult GetGiaTien(int id)
        {
            var giaSanPham = unitOfWork.SanPhamRepository.Get(x => x.Id == id, null, "GiaTien");

            if (giaSanPham == null)
            {
                return(NotFound());
            }
            GiaTien giaTien = new GiaTien
            {
            }

            return(Ok(giaSanPham));
        }
        public IHttpActionResult DeleteGiaTien(int id)
        {
            GiaTien giaTien = unitOfWork.GiaTienRepository.GetByID(id);

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

            unitOfWork.GiaTienRepository.Delete(giaTien);
            unitOfWork.Save();

            return(Ok(giaTien));
        }
Esempio n. 7
0
        public IHttpActionResult PutGiaSanPham(int id, GiaTien giaTien)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != giaTien.Id)
            {
                return(BadRequest());
            }

            unitOfWork.GiaTienRepository.Update(giaTien);
            var giaSP = new GiaTienDTO
            {
                SanPhamId = giaTien.SanPhamId,
                giaTien   = giaTien.giaTien
            };

            try
            {
                unitOfWork.Save();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SanPhamExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = giaTien.Id }, giaSP));
        }
Esempio n. 8
0
        public ActionResult timkiemnangcao(int?page, string tim, string gia, string cpu)
        {
            Intel cpu1 = new Intel()
            {
                V = "all", D = "Tất cả"
            };
            Intel cpu2 = new Intel()
            {
                V = "i3", D = "Core i3"
            };
            Intel cpu3 = new Intel()
            {
                V = "i5", D = "Core i5"
            };
            Intel cpu4 = new Intel()
            {
                V = "i7", D = "Core i7"
            };
            Intel cpu5 = new Intel()
            {
                V = "pen", D = "Pentinum"
            };
            Intel cpu6 = new Intel()
            {
                V = "adm", D = "ADM"
            };

            ViewBag.core = new SelectList(new List <Intel> {
                cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
            }, "V", "D", cpu1.V);

            GiaTien gt1 = new GiaTien()
            {
                V = "100", D = "Tất cả"
            };
            GiaTien gt2 = new GiaTien()
            {
                V = "10", D = "Dưới 10 triệu"
            };
            GiaTien gt3 = new GiaTien()
            {
                V = "15", D = "Dưới 15 triệu"
            };
            GiaTien gt4 = new GiaTien()
            {
                V = "20", D = "Dưới 20 triệu"
            };
            GiaTien gt5 = new GiaTien()
            {
                V = "25", D = "Dưới 25 triệu"
            };
            GiaTien gt6 = new GiaTien()
            {
                V = "26", D = "Trên 25 triệu"
            };

            ViewBag.Gia = new SelectList(new List <GiaTien> {
                gt1, gt2, gt3, gt4, gt5, gt6
            }, "V", "D", gt1.V);

            //ViewBag.ten = tim;
            //ViewBag.tien = gia;
            //ViewBag.cpu = cpu;
            if (tim != null)
            {
                if (gia == gt1.V && cpu == cpu1.V)
                {
                    var kq = lt.Sanphams.Where(x => x.TenSP.Contains(tim)).OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8);
                    ViewBag.Gia = new SelectList(new List <GiaTien> {
                        gt1, gt2, gt3, gt4, gt5, gt6
                    }, "V", "D", gia);
                    ViewBag.core = new SelectList(new List <Intel> {
                        cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
                    }, "V", "D", cpu);
                    ViewBag.ten  = tim;
                    ViewBag.tien = gia;
                    ViewBag.cpu  = cpu;
                    return(View(kq));
                }

                if (cpu == cpu1.V)
                {
                    if (gia == gt1.V)
                    {
                        var kq = lt.Sanphams.Where(x => x.TenSP.ToLower().Contains(tim.ToLower()))
                                 .OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8).OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8);
                        ViewBag.Gia = new SelectList(new List <GiaTien> {
                            gt1, gt2, gt3, gt4, gt5, gt6
                        }, "V", "D", gia);
                        ViewBag.core = new SelectList(new List <Intel> {
                            cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
                        }, "V", "D", cpu);
                        ViewBag.ten  = tim;
                        ViewBag.tien = gia;
                        ViewBag.cpu  = cpu;
                        return(View(kq));
                    }
                    if (gia == gt2.V)
                    {
                        var kq = lt.Sanphams.Where(x => x.TenSP.Contains(tim) && x.Giaban < 10000000).
                                 OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8);
                        ViewBag.Gia = new SelectList(new List <GiaTien> {
                            gt1, gt2, gt3, gt4, gt5, gt6
                        }, "V", "D", gia);
                        ViewBag.core = new SelectList(new List <Intel> {
                            cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
                        }, "V", "D", cpu);
                        ViewBag.ten  = tim;
                        ViewBag.tien = gia;
                        ViewBag.cpu  = cpu;
                        return(View(kq));
                    }
                    if (gia == gt3.V)
                    {
                        var kq = lt.Sanphams.Where(x => x.TenSP.Contains(tim) && x.Giaban >= 10000000 && x.Giaban < 15000000).
                                 OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8);
                        ViewBag.Gia = new SelectList(new List <GiaTien> {
                            gt1, gt2, gt3, gt4, gt5, gt6
                        }, "V", "D", gia);
                        ViewBag.core = new SelectList(new List <Intel> {
                            cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
                        }, "V", "D", cpu);
                        ViewBag.ten  = tim;
                        ViewBag.tien = gia;
                        ViewBag.cpu  = cpu;
                        return(View(kq));
                    }
                    if (gia == gt4.V)
                    {
                        var kq = lt.Sanphams.Where(x => x.TenSP.Contains(tim) && x.Giaban >= 15000000 && x.Giaban < 20000000).
                                 OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8);
                        ViewBag.Gia = new SelectList(new List <GiaTien> {
                            gt1, gt2, gt3, gt4, gt5, gt6
                        }, "V", "D", gia);
                        ViewBag.core = new SelectList(new List <Intel> {
                            cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
                        }, "V", "D", cpu);
                        ViewBag.ten  = tim;
                        ViewBag.tien = gia;
                        ViewBag.cpu  = cpu;
                        return(View(kq));
                    }
                    if (gia == gt5.V)
                    {
                        var kq = lt.Sanphams.Where(x => x.TenSP.Contains(tim) && x.Giaban >= 20000000 && x.Giaban < 25000000).
                                 OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8);
                        ViewBag.Gia = new SelectList(new List <GiaTien> {
                            gt1, gt2, gt3, gt4, gt5, gt6
                        }, "V", "D", gia);
                        ViewBag.core = new SelectList(new List <Intel> {
                            cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
                        }, "V", "D", cpu);
                        ViewBag.ten  = tim;
                        ViewBag.tien = gia;
                        ViewBag.cpu  = cpu;
                        return(View(kq));
                    }
                    if (gia == gt6.V)
                    {
                        var kq = lt.Sanphams.Where(x => x.TenSP.Contains(tim) && x.Giaban >= 25000000).
                                 OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8);
                        ViewBag.Gia = new SelectList(new List <GiaTien> {
                            gt1, gt2, gt3, gt4, gt5, gt6
                        }, "V", "D", gia);
                        ViewBag.core = new SelectList(new List <Intel> {
                            cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
                        }, "V", "D", cpu);
                        ViewBag.ten  = tim;
                        ViewBag.tien = gia;
                        ViewBag.cpu  = cpu;
                        return(View(kq));
                    }
                }
                if (gia == gt1.V)
                {
                    var kq = lt.Sanphams.Where(x => x.TenSP.ToLower().Contains(tim.ToLower()) &&
                                               x.cpu.ToLower().Contains(cpu.ToLower())).OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8);
                    ViewBag.Gia = new SelectList(new List <GiaTien> {
                        gt1, gt2, gt3, gt4, gt5, gt6
                    }, "V", "D", gia);
                    ViewBag.core = new SelectList(new List <Intel> {
                        cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
                    }, "V", "D", cpu);
                    ViewBag.ten  = tim;
                    ViewBag.tien = gia;
                    ViewBag.cpu  = cpu;
                    return(View(kq));
                }
                if (gia == gt2.V)
                {
                    var kq = lt.Sanphams.Where(x => x.TenSP.Contains(tim) && x.cpu.Contains(cpu) && x.Giaban < 10000000).
                             OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8);
                    ViewBag.Gia = new SelectList(new List <GiaTien> {
                        gt1, gt2, gt3, gt4, gt5, gt6
                    }, "V", "D", gia);
                    ViewBag.core = new SelectList(new List <Intel> {
                        cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
                    }, "V", "D", cpu);
                    ViewBag.ten  = tim;
                    ViewBag.tien = gia;
                    ViewBag.cpu  = cpu;
                    return(View(kq));
                }
                if (gia == gt3.V)
                {
                    var kq = lt.Sanphams.Where(x => x.TenSP.Contains(tim) && x.cpu.Contains(cpu) && x.Giaban >= 10000000 && x.Giaban < 15000000).
                             OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8);
                    ViewBag.Gia = new SelectList(new List <GiaTien> {
                        gt1, gt2, gt3, gt4, gt5, gt6
                    }, "V", "D", gia);
                    ViewBag.core = new SelectList(new List <Intel> {
                        cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
                    }, "V", "D", cpu);
                    ViewBag.ten  = tim;
                    ViewBag.tien = gia;
                    ViewBag.cpu  = cpu;
                    return(View(kq));
                }
                if (gia == gt4.V)
                {
                    var kq = lt.Sanphams.Where(x => x.TenSP.Contains(tim) && x.cpu.Contains(cpu) && x.Giaban >= 15000000 && x.Giaban < 20000000).
                             OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8);
                    ViewBag.Gia = new SelectList(new List <GiaTien> {
                        gt1, gt2, gt3, gt4, gt5, gt6
                    }, "V", "D", gia);
                    ViewBag.core = new SelectList(new List <Intel> {
                        cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
                    }, "V", "D", cpu);
                    ViewBag.ten  = tim;
                    ViewBag.tien = gia;
                    ViewBag.cpu  = cpu;
                    return(View(kq));
                }
                if (gia == gt5.V)
                {
                    var kq = lt.Sanphams.Where(x => x.TenSP.Contains(tim) && x.cpu.Contains(cpu) && x.Giaban >= 20000000 && x.Giaban < 25000000).
                             OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8);
                    ViewBag.Gia = new SelectList(new List <GiaTien> {
                        gt1, gt2, gt3, gt4, gt5, gt6
                    }, "V", "D", gia);
                    ViewBag.core = new SelectList(new List <Intel> {
                        cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
                    }, "V", "D", cpu);
                    ViewBag.ten  = tim;
                    ViewBag.tien = gia;
                    ViewBag.cpu  = cpu;
                    return(View(kq));
                }
                if (gia == gt6.V)
                {
                    var kq = lt.Sanphams.Where(x => x.TenSP.Contains(tim) && x.cpu.Contains(cpu) && x.Giaban >= 25000000).
                             OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8);
                    ViewBag.Gia = new SelectList(new List <GiaTien> {
                        gt1, gt2, gt3, gt4, gt5, gt6
                    }, "V", "D", gia);
                    ViewBag.core = new SelectList(new List <Intel> {
                        cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
                    }, "V", "D", cpu);
                    ViewBag.ten  = tim;
                    ViewBag.tien = gia;
                    ViewBag.cpu  = cpu;
                    return(View(kq));
                }
            }
            else if (string.IsNullOrEmpty(tim))
            {
                if (gia == gt1.V && cpu == cpu1.V)
                {
                    var kq = lt.Sanphams.OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8);
                    ViewBag.Gia = new SelectList(new List <GiaTien> {
                        gt1, gt2, gt3, gt4, gt5, gt6
                    }, "V", "D", gia);
                    ViewBag.core = new SelectList(new List <Intel> {
                        cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
                    }, "V", "D", cpu);
                    ViewBag.ten  = tim;
                    ViewBag.tien = gia;
                    return(View(kq));
                }
                if (cpu == cpu1.V)
                {
                    if (gia == gt1.V)
                    {
                        var kq = lt.Sanphams.OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8);
                        ViewBag.Gia = new SelectList(new List <GiaTien> {
                            gt1, gt2, gt3, gt4, gt5, gt6
                        }, "V", "D", gia);
                        ViewBag.core = new SelectList(new List <Intel> {
                            cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
                        }, "V", "D", cpu);
                        ViewBag.ten  = tim;
                        ViewBag.tien = gia;
                        ViewBag.cpu  = cpu;
                        return(View(kq));
                    }
                    if (gia == gt2.V)
                    {
                        var kq = lt.Sanphams.Where(x => x.Giaban < 10000000).
                                 OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8);
                        ViewBag.Gia = new SelectList(new List <GiaTien> {
                            gt1, gt2, gt3, gt4, gt5, gt6
                        }, "V", "D", gia);
                        ViewBag.core = new SelectList(new List <Intel> {
                            cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
                        }, "V", "D", cpu);
                        ViewBag.ten  = tim;
                        ViewBag.tien = gia;
                        ViewBag.cpu  = cpu;
                        return(View(kq));
                    }
                    if (gia == gt3.V)
                    {
                        var kq = lt.Sanphams.Where(x => x.Giaban >= 10000000 && x.Giaban < 15000000).
                                 OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8);
                        ViewBag.Gia = new SelectList(new List <GiaTien> {
                            gt1, gt2, gt3, gt4, gt5, gt6
                        }, "V", "D", gia);
                        ViewBag.core = new SelectList(new List <Intel> {
                            cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
                        }, "V", "D", cpu);
                        ViewBag.ten  = tim;
                        ViewBag.tien = gia;
                        ViewBag.cpu  = cpu;
                        return(View(kq));
                    }
                    if (gia == gt4.V)
                    {
                        var kq = lt.Sanphams.Where(x => x.Giaban >= 15000000 && x.Giaban < 20000000).
                                 OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8);
                        ViewBag.Gia = new SelectList(new List <GiaTien> {
                            gt1, gt2, gt3, gt4, gt5, gt6
                        }, "V", "D", gia);
                        ViewBag.core = new SelectList(new List <Intel> {
                            cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
                        }, "V", "D", cpu);
                        ViewBag.ten  = tim;
                        ViewBag.tien = gia;
                        ViewBag.cpu  = cpu;
                        return(View(kq));
                    }
                    if (gia == gt5.V)
                    {
                        var kq = lt.Sanphams.Where(x => x.Giaban >= 20000000 &&
                                                   x.Giaban < 25000000).
                                 OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8);
                        ViewBag.Gia = new SelectList(new List <GiaTien> {
                            gt1, gt2, gt3, gt4, gt5, gt6
                        }, "V", "D", gia);
                        ViewBag.core = new SelectList(new List <Intel> {
                            cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
                        }, "V", "D", cpu);
                        ViewBag.ten  = tim;
                        ViewBag.tien = gia;
                        ViewBag.cpu  = cpu;
                        return(View(kq));
                    }
                    if (gia == gt6.V)
                    {
                        var kq = lt.Sanphams.Where(x => x.Giaban >= 25000000).
                                 OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8);
                        ViewBag.Gia = new SelectList(new List <GiaTien> {
                            gt1, gt2, gt3, gt4, gt5, gt6
                        }, "V", "D", gia);
                        ViewBag.core = new SelectList(new List <Intel> {
                            cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
                        }, "V", "D", cpu);
                        ViewBag.ten  = tim;
                        ViewBag.tien = gia;
                        ViewBag.cpu  = cpu;
                        return(View(kq));
                    }
                }
                if (gia == gt1.V)
                {
                    var kq = lt.Sanphams.Where(x => x.cpu.ToLower().Contains(cpu.ToLower()))
                             .OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8);
                    ViewBag.Gia = new SelectList(new List <GiaTien> {
                        gt1, gt2, gt3, gt4, gt5, gt6
                    }, "V", "D", gia);
                    ViewBag.core = new SelectList(new List <Intel> {
                        cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
                    }, "V", "D", cpu);
                    ViewBag.ten  = tim;
                    ViewBag.tien = gia;
                    ViewBag.cpu  = cpu;
                    return(View(kq));
                }

                if (gia == gt2.V)
                {
                    var kq = lt.Sanphams.Where(x => x.Giaban < 10000000 && x.cpu.Contains(cpu)).
                             OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8);
                    ViewBag.Gia = new SelectList(new List <GiaTien> {
                        gt1, gt2, gt3, gt4, gt5, gt6
                    }, "V", "D", gia);
                    ViewBag.core = new SelectList(new List <Intel> {
                        cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
                    }, "V", "D", cpu);
                    ViewBag.ten  = tim;
                    ViewBag.tien = gia;
                    ViewBag.cpu  = cpu;
                    return(View(kq));
                }
                if (gia == gt3.V)
                {
                    var kq = lt.Sanphams.Where(x => x.Giaban >= 10000000 && x.Giaban < 15000000 && x.cpu.Contains(cpu)).
                             OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8);
                    ViewBag.Gia = new SelectList(new List <GiaTien> {
                        gt1, gt2, gt3, gt4, gt5, gt6
                    }, "V", "D", gia);
                    ViewBag.core = new SelectList(new List <Intel> {
                        cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
                    }, "V", "D", cpu);
                    ViewBag.ten  = tim;
                    ViewBag.tien = gia;
                    ViewBag.cpu  = cpu;
                    return(View(kq));
                }
                if (gia == gt4.V)
                {
                    var kq = lt.Sanphams.Where(x => x.Giaban >= 15000000 && x.Giaban < 20000000 && x.cpu.Contains(cpu)).
                             OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8);
                    ViewBag.Gia = new SelectList(new List <GiaTien> {
                        gt1, gt2, gt3, gt4, gt5, gt6
                    }, "V", "D", gia);
                    ViewBag.core = new SelectList(new List <Intel> {
                        cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
                    }, "V", "D", cpu);
                    ViewBag.ten  = tim;
                    ViewBag.tien = gia;
                    ViewBag.cpu  = cpu;
                    return(View(kq));
                }
                if (gia == gt5.V)
                {
                    var kq = lt.Sanphams.Where(x => x.Giaban >= 20000000 && x.Giaban < 25000000 && x.cpu.Contains(cpu)).
                             OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8);
                    ViewBag.Gia = new SelectList(new List <GiaTien> {
                        gt1, gt2, gt3, gt4, gt5, gt6
                    }, "V", "D", gia);
                    ViewBag.core = new SelectList(new List <Intel> {
                        cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
                    }, "V", "D", cpu);
                    ViewBag.ten  = tim;
                    ViewBag.tien = gia;
                    ViewBag.cpu  = cpu;
                    return(View(kq));
                }
                if (gia == gt6.V)
                {
                    var kq = lt.Sanphams.Where(x => x.Giaban >= 25000000 && x.cpu.Contains(cpu)).
                             OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8);
                    ViewBag.Gia = new SelectList(new List <GiaTien> {
                        gt1, gt2, gt3, gt4, gt5, gt6
                    }, "V", "D", gia);
                    ViewBag.core = new SelectList(new List <Intel> {
                        cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
                    }, "V", "D", cpu);
                    ViewBag.ten  = tim;
                    ViewBag.tien = gia;
                    ViewBag.cpu  = cpu;
                    return(View(kq));
                }
            }
            return(View());
        }
Esempio n. 9
0
        public ActionResult timkiemnangcao(FormCollection form, int?page, int?pagesize)
        {
            var     tim = form["ten"];
            var     gia = form["gia"];
            var     cpu = form["core"];
            GiaTien gt1 = new GiaTien()
            {
                V = "100", D = "Tất cả"
            };
            GiaTien gt2 = new GiaTien()
            {
                V = "10", D = "Dưới 10 triệu"
            };
            GiaTien gt3 = new GiaTien()
            {
                V = "15", D = "Dưới 15 triệu"
            };
            GiaTien gt4 = new GiaTien()
            {
                V = "20", D = "Dưới 20 triệu"
            };
            GiaTien gt5 = new GiaTien()
            {
                V = "25", D = "Dưới 25 triệu"
            };
            GiaTien gt6 = new GiaTien()
            {
                V = "26", D = "Trên 25 triệu"
            };

            ViewBag.Gia = new SelectList(new List <GiaTien> {
                gt1, gt2, gt3, gt4, gt5, gt6
            }, "V", "D", gt4.V);

            Intel cpu1 = new Intel()
            {
                V = "all", D = "Tất cả"
            };
            Intel cpu2 = new Intel()
            {
                V = "i3", D = "Core i3"
            };
            Intel cpu3 = new Intel()
            {
                V = "i5", D = "Core i5"
            };
            Intel cpu4 = new Intel()
            {
                V = "i7", D = "Core i7"
            };
            Intel cpu5 = new Intel()
            {
                V = "pen", D = "Pentinum"
            };
            Intel cpu6 = new Intel()
            {
                V = "adm", D = "ADM"
            };

            ViewBag.core = new SelectList(new List <Intel> {
                cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
            }, "V", "D", cpu1.V);

            if (tim.Count() == 0 && gia.Count() > 0)
            {
                if (form["gia"] == gt1.V && form["core"] == cpu1.V)
                {
                    var kq = lt.Sanphams.OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8);
                    ViewBag.Gia = new SelectList(new List <GiaTien> {
                        gt1, gt2, gt3, gt4, gt5, gt6
                    }, "V", "D", gia);
                    ViewBag.core = new SelectList(new List <Intel> {
                        cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
                    }, "V", "D", cpu);
                    ViewBag.ten  = tim;
                    ViewBag.tien = gia;
                    ViewBag.cpu  = cpu;
                    return(View(kq));
                }
                if (form["core"] == cpu1.V)
                {
                    if (form["gia"] == gt1.V)
                    {
                        var kq = lt.Sanphams
                                 .OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8);
                        ViewBag.Gia = new SelectList(new List <GiaTien> {
                            gt1, gt2, gt3, gt4, gt5, gt6
                        }, "V", "D", gia);
                        ViewBag.core = new SelectList(new List <Intel> {
                            cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
                        }, "V", "D", cpu);
                        ViewBag.ten  = tim;
                        ViewBag.tien = gia;
                        ViewBag.cpu  = cpu;
                        return(View(kq));
                    }
                    if (form["gia"] == gt2.V)
                    {
                        var kq = lt.Sanphams.Where(x => x.Giaban < 10000000).
                                 OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8);
                        ViewBag.Gia = new SelectList(new List <GiaTien> {
                            gt1, gt2, gt3, gt4, gt5, gt6
                        }, "V", "D", gia);
                        ViewBag.core = new SelectList(new List <Intel> {
                            cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
                        }, "V", "D", cpu);
                        ViewBag.ten  = tim;
                        ViewBag.tien = gia;
                        ViewBag.cpu  = cpu;
                        return(View(kq));
                    }
                    if (form["gia"] == gt3.V)
                    {
                        var kq = lt.Sanphams.Where(x => x.Giaban >= 10000000 && x.Giaban < 15000000).
                                 OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8);
                        ViewBag.Gia = new SelectList(new List <GiaTien> {
                            gt1, gt2, gt3, gt4, gt5, gt6
                        }, "V", "D", gia);
                        ViewBag.core = new SelectList(new List <Intel> {
                            cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
                        }, "V", "D", cpu);
                        ViewBag.ten  = tim;
                        ViewBag.tien = gia;
                        ViewBag.cpu  = cpu;
                        return(View(kq));
                    }
                    if (form["gia"] == gt4.V)
                    {
                        var kq = lt.Sanphams.Where(x => x.Giaban >= 15000000 && x.Giaban < 20000000).
                                 OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8);
                        ViewBag.Gia = new SelectList(new List <GiaTien> {
                            gt1, gt2, gt3, gt4, gt5, gt6
                        }, "V", "D", gia);
                        ViewBag.core = new SelectList(new List <Intel> {
                            cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
                        }, "V", "D", cpu);
                        ViewBag.ten  = tim;
                        ViewBag.tien = gia;
                        ViewBag.cpu  = cpu;
                        return(View(kq));
                    }
                    if (form["gia"] == gt5.V)
                    {
                        var kq = lt.Sanphams.Where(x => x.Giaban >= 20000000 && x.Giaban < 25000000).
                                 OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8);
                        ViewBag.Gia = new SelectList(new List <GiaTien> {
                            gt1, gt2, gt3, gt4, gt5, gt6
                        }, "V", "D", gia);
                        ViewBag.core = new SelectList(new List <Intel> {
                            cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
                        }, "V", "D", cpu);
                        ViewBag.ten  = tim;
                        ViewBag.tien = gia;
                        ViewBag.cpu  = cpu;
                        return(View(kq));
                    }
                    if (form["gia"] == gt6.V)
                    {
                        var kq = lt.Sanphams.Where(x => x.Giaban >= 25000000).
                                 OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8);
                        ViewBag.Gia = new SelectList(new List <GiaTien> {
                            gt1, gt2, gt3, gt4, gt5, gt6
                        }, "V", "D", gia);
                        ViewBag.core = new SelectList(new List <Intel> {
                            cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
                        }, "V", "D", cpu);
                        ViewBag.ten  = tim;
                        ViewBag.tien = gia;
                        ViewBag.cpu  = cpu;
                        return(View(kq));
                    }
                }
                if (form["gia"] == gt1.V)
                {
                    var kq = lt.Sanphams.Where(x => x.cpu.ToLower().Contains(cpu.ToLower()))
                             .OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8);
                    ViewBag.Gia = new SelectList(new List <GiaTien> {
                        gt1, gt2, gt3, gt4, gt5, gt6
                    }, "V", "D", gia);
                    ViewBag.core = new SelectList(new List <Intel> {
                        cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
                    }, "V", "D", cpu);
                    ViewBag.ten  = tim;
                    ViewBag.tien = gia;
                    ViewBag.cpu  = cpu;
                    return(View(kq));
                }
                if (form["gia"] == gt2.V)
                {
                    var kq = lt.Sanphams.Where(x => x.Giaban < 10000000 && x.cpu.Contains(cpu)).OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8);
                    ViewBag.Gia = new SelectList(new List <GiaTien> {
                        gt1, gt2, gt3, gt4, gt5, gt6
                    }, "V", "D", gia);
                    ViewBag.core = new SelectList(new List <Intel> {
                        cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
                    }, "V", "D", cpu);
                    ViewBag.ten  = tim;
                    ViewBag.tien = gia;
                    ViewBag.cpu  = cpu;
                    return(View(kq));
                }
                if (form["gia"] == gt3.V)
                {
                    var kq = lt.Sanphams.Where(x => x.Giaban >= 10000000 &&
                                               x.Giaban < 15000000 && x.cpu.Contains(cpu)).
                             OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8);
                    ViewBag.Gia = new SelectList(new List <GiaTien> {
                        gt1, gt2, gt3, gt4, gt5, gt6
                    }, "V", "D", gia);
                    ViewBag.core = new SelectList(new List <Intel> {
                        cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
                    }, "V", "D", cpu);
                    ViewBag.ten  = tim;
                    ViewBag.tien = gia;
                    ViewBag.cpu  = cpu;
                    return(View(kq));
                }
                if (form["gia"] == gt4.V)
                {
                    var kq = lt.Sanphams.Where(x => x.Giaban >= 15000000 &&
                                               x.Giaban < 20000000 && x.cpu.Contains(cpu))
                             .OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8);
                    ViewBag.Gia = new SelectList(new List <GiaTien> {
                        gt1, gt2, gt3, gt4, gt5, gt6
                    }, "V", "D", gia);
                    ViewBag.core = new SelectList(new List <Intel> {
                        cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
                    }, "V", "D", cpu);
                    ViewBag.ten  = tim;
                    ViewBag.tien = gia;
                    ViewBag.cpu  = cpu;
                    return(View(kq));
                }
                if (form["gia"] == gt5.V)
                {
                    var kq = lt.Sanphams.Where(x => x.Giaban >= 20000000 &&
                                               x.Giaban < 25000000 && x.cpu.Contains(cpu))
                             .OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8);
                    ViewBag.Gia = new SelectList(new List <GiaTien> {
                        gt1, gt2, gt3, gt4, gt5, gt6
                    }, "V", "D", gia);
                    ViewBag.core = new SelectList(new List <Intel> {
                        cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
                    }, "V", "D", cpu);
                    ViewBag.ten  = tim;
                    ViewBag.tien = gia;
                    ViewBag.cpu  = cpu;
                    return(View(kq));
                }
                if (form["gia"] == gt6.V)
                {
                    var kq = lt.Sanphams.Where(x => x.Giaban >= 25000000 && x.cpu.Contains(cpu))
                             .OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8);
                    ViewBag.Gia = new SelectList(new List <GiaTien> {
                        gt1, gt2, gt3, gt4, gt5, gt6
                    }, "V", "D", gia);
                    ViewBag.core = new SelectList(new List <Intel> {
                        cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
                    }, "V", "D", cpu);
                    ViewBag.ten  = tim;
                    ViewBag.tien = gia;
                    ViewBag.cpu  = cpu;
                    return(View(kq));
                }
            }
            else if (tim.Count() > 0)
            {
                if (form["gia"] == gt1.V && form["core"] == cpu1.V)
                {
                    var kq = lt.Sanphams.Where(x => x.TenSP.Contains(tim)).OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8);
                    ViewBag.Gia = new SelectList(new List <GiaTien> {
                        gt1, gt2, gt3, gt4, gt5, gt6
                    }, "V", "D", gia);
                    ViewBag.core = new SelectList(new List <Intel> {
                        cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
                    }, "V", "D", cpu);
                    ViewBag.ten  = tim;
                    ViewBag.tien = gia;
                    ViewBag.cpu  = cpu;
                    return(View(kq));
                }
                if (form["core"] == cpu1.V)
                {
                    if (form["gia"] == gt1.V)
                    {
                        var kq = lt.Sanphams.Where(x => x.TenSP.ToLower().Contains(tim.ToLower()))
                                 .OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8);
                        ViewBag.Gia = new SelectList(new List <GiaTien> {
                            gt1, gt2, gt3, gt4, gt5, gt6
                        }, "V", "D", gia);
                        ViewBag.core = new SelectList(new List <Intel> {
                            cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
                        }, "V", "D", cpu);
                        ViewBag.ten  = tim;
                        ViewBag.tien = gia;
                        ViewBag.cpu  = cpu;
                        return(View(kq));
                    }
                    if (form["gia"] == gt2.V)
                    {
                        var kq = lt.Sanphams.Where(x => x.TenSP.Contains(tim) && x.Giaban < 10000000).
                                 OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8);
                        ViewBag.Gia = new SelectList(new List <GiaTien> {
                            gt1, gt2, gt3, gt4, gt5, gt6
                        }, "V", "D", gia);
                        ViewBag.core = new SelectList(new List <Intel> {
                            cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
                        }, "V", "D", cpu);
                        ViewBag.ten  = tim;
                        ViewBag.tien = gia;
                        ViewBag.cpu  = cpu;
                        return(View(kq));
                    }
                    if (form["gia"] == gt3.V)
                    {
                        var kq = lt.Sanphams.Where(x => x.TenSP.Contains(tim) && x.Giaban >= 10000000 && x.Giaban < 15000000).
                                 OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8);
                        ViewBag.Gia = new SelectList(new List <GiaTien> {
                            gt1, gt2, gt3, gt4, gt5, gt6
                        }, "V", "D", gia);
                        ViewBag.core = new SelectList(new List <Intel> {
                            cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
                        }, "V", "D", cpu);
                        ViewBag.ten  = tim;
                        ViewBag.tien = gia;
                        ViewBag.cpu  = cpu;
                        return(View(kq));
                    }
                    if (form["gia"] == gt4.V)
                    {
                        var kq = lt.Sanphams.Where(x => x.TenSP.Contains(tim) && x.Giaban >= 15000000 && x.Giaban < 20000000).
                                 OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8);
                        ViewBag.Gia = new SelectList(new List <GiaTien> {
                            gt1, gt2, gt3, gt4, gt5, gt6
                        }, "V", "D", gia);
                        ViewBag.core = new SelectList(new List <Intel> {
                            cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
                        }, "V", "D", cpu);
                        ViewBag.ten  = tim;
                        ViewBag.tien = gia;
                        ViewBag.cpu  = cpu;
                        return(View(kq));
                    }
                    if (form["gia"] == gt5.V)
                    {
                        var kq = lt.Sanphams.Where(x => x.TenSP.Contains(tim) && x.Giaban >= 20000000 && x.Giaban < 25000000).
                                 OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8);
                        ViewBag.Gia = new SelectList(new List <GiaTien> {
                            gt1, gt2, gt3, gt4, gt5, gt6
                        }, "V", "D", gia);
                        ViewBag.core = new SelectList(new List <Intel> {
                            cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
                        }, "V", "D", cpu);
                        ViewBag.ten  = tim;
                        ViewBag.tien = gia;
                        ViewBag.cpu  = cpu;
                        return(View(kq));
                    }
                    if (form["gia"] == gt6.V)
                    {
                        var kq = lt.Sanphams.Where(x => x.TenSP.Contains(tim) && x.Giaban >= 25000000).
                                 OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8);
                        ViewBag.Gia = new SelectList(new List <GiaTien> {
                            gt1, gt2, gt3, gt4, gt5, gt6
                        }, "V", "D", gia);
                        ViewBag.core = new SelectList(new List <Intel> {
                            cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
                        }, "V", "D", cpu);
                        ViewBag.ten  = tim;
                        ViewBag.tien = gia;
                        ViewBag.cpu  = cpu;
                        return(View(kq));
                    }
                }
                if (form["gia"] == gt1.V)
                {
                    var kq = lt.Sanphams.Where(x => x.TenSP.ToLower().Contains(tim.ToLower()) &&
                                               x.cpu.ToLower().Contains(cpu.ToLower())).OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8);
                    ViewBag.Gia = new SelectList(new List <GiaTien> {
                        gt1, gt2, gt3, gt4, gt5, gt6
                    }, "V", "D", gia);
                    ViewBag.core = new SelectList(new List <Intel> {
                        cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
                    }, "V", "D", cpu);
                    ViewBag.ten  = tim;
                    ViewBag.tien = gia;
                    ViewBag.cpu  = cpu;
                    return(View(kq));
                }
                if (form["gia"] == gt2.V)
                {
                    var kq = lt.Sanphams.Where(x => x.TenSP.Contains(tim) && x.cpu.Contains(cpu) && x.Giaban < 10000000)
                             .OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8);
                    ViewBag.Gia = new SelectList(new List <GiaTien> {
                        gt1, gt2, gt3, gt4, gt5, gt6
                    }, "V", "D", gia);
                    ViewBag.core = new SelectList(new List <Intel> {
                        cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
                    }, "V", "D", cpu);
                    ViewBag.ten  = tim;
                    ViewBag.tien = gia;
                    ViewBag.cpu  = cpu;
                    return(View(kq));
                }
                if (form["gia"] == gt3.V)
                {
                    var kq = lt.Sanphams.Where(x => x.TenSP.Contains(tim) && x.cpu.Contains(cpu) && x.Giaban >= 10000000 && x.Giaban < 15000000)
                             .OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8);
                    ViewBag.Gia = new SelectList(new List <GiaTien> {
                        gt1, gt2, gt3, gt4, gt5, gt6
                    }, "V", "D", gia);
                    ViewBag.core = new SelectList(new List <Intel> {
                        cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
                    }, "V", "D", cpu);
                    ViewBag.ten  = tim;
                    ViewBag.tien = gia;
                    ViewBag.cpu  = cpu;
                    return(View(kq));
                }
                if (form["gia"] == gt4.V)
                {
                    var kq = lt.Sanphams.Where(x => x.TenSP.Contains(tim) &&
                                               x.cpu.Contains(cpu) && x.Giaban >= 15000000 && x.Giaban < 20000000)
                             .OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8);
                    ViewBag.Gia = new SelectList(new List <GiaTien> {
                        gt1, gt2, gt3, gt4, gt5, gt6
                    }, "V", "D", gia);
                    ViewBag.core = new SelectList(new List <Intel> {
                        cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
                    }, "V", "D", cpu);
                    ViewBag.ten  = tim;
                    ViewBag.tien = gia;
                    ViewBag.cpu  = cpu;
                    return(View(kq));
                }
                if (form["gia"] == gt5.V)
                {
                    var kq = lt.Sanphams.Where(x => x.TenSP.Contains(tim) && x.cpu.Contains(cpu) &&
                                               x.Giaban >= 20000000 && x.Giaban < 25000000)
                             .OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8);
                    ViewBag.Gia = new SelectList(new List <GiaTien> {
                        gt1, gt2, gt3, gt4, gt5, gt6
                    }, "V", "D", gia);
                    ViewBag.core = new SelectList(new List <Intel> {
                        cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
                    }, "V", "D", cpu);
                    ViewBag.ten  = tim;
                    ViewBag.tien = gia;
                    ViewBag.cpu  = cpu;
                    return(View(kq));
                }
                if (form["gia"] == gt6.V)
                {
                    var kq = lt.Sanphams.Where(x => x.TenSP.Contains(tim) && x.cpu.Contains(cpu) && x.Giaban >= 25000000)
                             .OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8);
                    ViewBag.Gia = new SelectList(new List <GiaTien> {
                        gt1, gt2, gt3, gt4, gt5, gt6
                    }, "V", "D", gia);
                    ViewBag.core = new SelectList(new List <Intel> {
                        cpu1, cpu2, cpu3, cpu4, cpu5, cpu6
                    }, "V", "D", cpu);
                    ViewBag.ten  = tim;
                    ViewBag.tien = gia;
                    ViewBag.cpu  = cpu;
                    return(View(kq));
                }
            }
            return(View());
        }