public ActionResult New()
        {
            var role      = _context.Roles.Single(x => x.Name == RoleName.SalesMan);
            var viewModel = new PhanCongSalesViewModel
            {
                NhanViens = _context.NhanViens.Where(x => x.TrangThai == 1 &&
                                                     x.Account.Roles.FirstOrDefault().RoleId == role.Id).ToList(),
                DuAns = _context.DuAns.Where(x => x.TrangThai == 1 &&
                                             _context.NhaDats.Where(y => y.DuAnId == x.Id).Count() > 0).ToList(),
                NhaDats           = _context.NhaDats.Include(x => x.LoaiNhaDat).Where(x => _context.PhanCongSales.FirstOrDefault(y => y.NhaDatId == x.Id) == null),
                TrangThaiPhanCong = SelectOptions.getTrangThaiPhanCongSales
            };

            return(View("PhanCongSalesForm", viewModel));
        }
Пример #2
0
        public ActionResult Search(int?trangThai, int?duAnId)
        {
            var userId        = User.Identity.GetUserId();
            var salesMan      = _context.NhanViens.Single(y => y.Account.Id == userId);
            var phanCongsInDb = _context.PhanCongSales.Include(x => x.NhaDat.DuAn).Include(x => x.NhanVienSales)
                                .Where(x => x.NhanVienSales.Id == salesMan.Id).ToList();
            var phanCongViewModels = new List <PhanCongSalesViewModel>();
            var duAns = new List <DuAn>();

            foreach (var phanCongInDb in phanCongsInDb)
            {
                var phanCong = new PhanCongSalesViewModel(phanCongInDb);
                phanCong.NhaDat        = phanCongInDb.NhaDat;
                phanCong.NhanVienSales = phanCongInDb.NhanVienSales;
                phanCongViewModels.Add(phanCong);
                duAns.Add(phanCongInDb.NhaDat.DuAn);
            }
            var role      = _context.Roles.Single(x => x.Name == RoleName.SalesMan);
            var viewModel = new QuanLyBaoCaoCongViecViewModel
            {
                PhanCongSales     = phanCongViewModels,
                TrangThaiPhanCong = SelectOptions.getTrangThaiPhanCongSales,
                DuAns             = duAns
            };

            if (trangThai.HasValue)
            {
                viewModel.TrangThai     = trangThai.Value;
                viewModel.PhanCongSales = viewModel.PhanCongSales.Where(x => x.TrangThai == trangThai);
            }

            if (duAnId.HasValue)
            {
                viewModel.DuAnId        = duAnId.Value;
                viewModel.PhanCongSales = viewModel.PhanCongSales.Where(x => x.NhaDat.DuAn.Id == duAnId);
            }

            return(View("Index", viewModel));
        }
        public ActionResult Save(PhanCongSales phanCongSales)
        {
            var role = _context.Roles.Single(x => x.Name == RoleName.SalesMan);

            if (!ModelState.IsValid)
            {
                var errors    = ModelState.Values.SelectMany(v => v.Errors);
                var viewModel = new PhanCongSalesViewModel
                {
                    NhanViens = _context.NhanViens.Where(x => x.TrangThai == 1 &&
                                                         x.Account.Roles.FirstOrDefault().RoleId == role.Id).ToList(),
                    DuAns = _context.DuAns.Where(x => x.TrangThai == 1 &&
                                                 _context.NhaDats.Where(y => y.DuAnId == x.Id).Count() > 0).ToList(),
                    NhaDats           = _context.NhaDats.Include(x => x.LoaiNhaDat).Where(x => _context.PhanCongSales.FirstOrDefault(y => y.NhaDatId == x.Id) == null),
                    TrangThaiPhanCong = SelectOptions.getTrangThaiPhanCongSales
                };
                return(View("PhanCongSalesForm", viewModel));
            }

            if (phanCongSales.Id == 0)
            {
                phanCongSales.TrangThai = 1;
                phanCongSales.NgayTao   = DateTime.Now;
                var userId = User.Identity.GetUserId();
                phanCongSales.NguoTao = _context.NhanViens.FirstOrDefault(x => x.AccountId == userId).HoTen;
                _context.PhanCongSales.Add(phanCongSales);
                TempData["success"] = "Thêm thành công";
            }
            else
            {
                var phanCongInDb = _context.PhanCongSales.Single(x => x.Id == phanCongSales.Id);
                phanCongInDb.TrangThai     = phanCongSales.TrangThai;
                phanCongInDb.DaTinhHoaHong = phanCongSales.DaTinhHoaHong;
                TempData["success"]        = "Cập nhật thành công";
            }
            _context.SaveChanges();

            return(RedirectToAction("Index", "QuanLyPhanCongSales"));
        }
Пример #4
0
        // GET: Admin/QuanLyBaoCaoCongViec
        public ActionResult Index()
        {
            if (TempData["success"] != null)
            {
                ViewBag.Success = TempData["success"].ToString();
                TempData.Remove("success");
            }
            if (TempData["error"] != null)
            {
                ViewBag.Error = TempData["error"].ToString();
                TempData.Remove("error");
            }

            var userId        = User.Identity.GetUserId();
            var salesMan      = _context.NhanViens.Single(y => y.Account.Id == userId);
            var phanCongsInDb = _context.PhanCongSales.Include(x => x.NhaDat).Include(x => x.NhaDat.DuAn).Include(x => x.NhanVienSales)
                                .Where(x => x.NhanVienSales.Id == salesMan.Id).ToList();
            var phanCongViewModels = new List <PhanCongSalesViewModel>();
            var duAns = new List <DuAn>();

            foreach (var phanCongInDb in phanCongsInDb)
            {
                var phanCong = new PhanCongSalesViewModel(phanCongInDb);
                phanCong.NhaDat        = phanCongInDb.NhaDat;
                phanCong.NhanVienSales = phanCongInDb.NhanVienSales;
                phanCongViewModels.Add(phanCong);
                duAns.Add(phanCongInDb.NhaDat.DuAn);
            }
            var role      = _context.Roles.Single(x => x.Name == RoleName.SalesMan);
            var viewModel = new QuanLyBaoCaoCongViecViewModel
            {
                PhanCongSales     = phanCongViewModels,
                TrangThaiPhanCong = SelectOptions.getTrangThaiPhanCongSales,
                DuAns             = duAns
            };

            return(View(viewModel));
        }
        public ActionResult Edit(int id)
        {
            var phanCongSales = _context.PhanCongSales.Include(x => x.NhaDat).Include(x => x.NhaDat.DuAn).Include(x => x.NhanVienSales).FirstOrDefault(x => x.Id == id);

            if (phanCongSales == null)
            {
                return(HttpNotFound());
            }
            var role      = _context.Roles.Single(x => x.Name == RoleName.SalesMan);
            var viewModel = new PhanCongSalesViewModel(phanCongSales)
            {
                NhanViens = _context.NhanViens.Where(x => x.TrangThai == 1 &&
                                                     x.Account.Roles.FirstOrDefault().RoleId == role.Id).ToList(),
                DuAns = _context.DuAns.Where(x => x.TrangThai == 1 &&
                                             _context.NhaDats.Where(y => y.DuAnId == x.Id).Count() > 0).ToList(),
                NhaDats           = _context.NhaDats.Include(x => x.LoaiNhaDat).Where(x => _context.PhanCongSales.FirstOrDefault(y => y.NhaDatId == x.Id) == null),
                TrangThaiPhanCong = SelectOptions.getTrangThaiPhanCongSales
            };

            viewModel.NhaDat        = phanCongSales.NhaDat;
            viewModel.NhanVienSales = phanCongSales.NhanVienSales;
            return(View("PhanCongSalesForm", viewModel));
        }