public ActionResult Create(CreatePDistributorViewModel model)
        {
            logger.Info("Start Create(POST) - PDistributorController");
            var pDis = new PotentialDistributor
            {
                idDistributor = _pdistributorService.GeneratePDistributorId(),
                name          = model.name,
                address       = model.address,
                Email         = model.Email,
                phone         = model.phone,
                createdDate   = DateTime.Now,
                status        = 0,
            };
            var rep = new Representative
            {
                idRepresentative = _representativeService.GenerateRepresentativeId(),
                name             = model.rep_name,
                email            = model.rep_email,
                title            = model.title,
                phone            = model.rep_phone,
                PDistributor     = pDis.idDistributor,
            };
            var result = _pdistributorService.Create(pDis, rep);

            if (result == true)
            {
                logger.Info("Success: Complete Create(POST) - PDistributorController");
                TempData["success"] = "Thành công";
                return(RedirectToAction("Create"));
            }
            else
            {
                logger.Info("Fail: Create(POST) - PDistributorController");
                TempData["fail"] = result;
                return(View(model));
            }
        }
        public ActionResult CreateContract(ContractDistributorVM model, [Bind(Prefix = "ContractViewModel")] ContractViewModel con, [Bind(Prefix = "DistributorViewModel")] DistributorViewModel dis, [Bind(Prefix = "RepresentativeViewModel")] RepresentativeViewModel rep)
        {
            isAdminLogged();
            logger.Info("Start controller to create contract...");
            var  user = Session["admin"] as Account;
            bool result;
            var  _con = new Contract();

            _con.area               = con.area;
            _con.beginDate          = con.beginDate;
            _con.commission         = con.commission;
            _con.disType            = con.disType;
            _con.expiredDate        = con.expiredDate;
            _con.maxDebt            = con.maxDebt;
            _con.minOrderTotalValue = con.minOrderTotalValue;
            _con.note               = con.note;
            _con.staff              = staff_Service.GetByAccount(user.UserName).idStaff;

            if (rep.idRepresentative == 0)  // Create contract for old distributor
            {
                Representative _rep = new Representative
                {
                    idRepresentative = rep_Service.GenerateRepresentativeId(),
                    name             = rep.name,
                    title            = rep.title,
                    phone            = rep.phone,
                    email            = rep.email,
                    Distributor      = dis.idDistributor
                };
                _con.Representative1 = _rep;
                _con.distributor     = dis.idDistributor;
                result = con_Service.CreateContract(_con, false);
            }
            else        // Create contract for potential distributor
            {
                Distributor _dis = new Distributor
                {
                    idDistributor = dis_Service.GenerateDistributorId(),
                    name          = dis.name,
                    address       = dis.address,
                    Email         = dis.Email,
                    phone         = dis.phone,
                    createdDate   = DateTime.Now,
                    updatedDate   = DateTime.Now,
                    debt          = 0,
                    status        = true
                };
                _con.Distributor1   = _dis; // _dis.idDistributor;
                _con.representative = rep.idRepresentative;
                result = con_Service.CreateContract(_con, true);
                //pDis_Service.UpdateStatus(dis.idDistributor, 5, "Đã tạo hợp đồng");
            }
            if (result == true)
            {
                TempData["success"] = "Thành công";
                model = new ContractDistributorVM();
                logger.Info("End: Successful....");
            }
            else
            {
                TempData["fail"] = "Thất bại";
                logger.Info("End: Unsuccessful....");
            }

            return(RedirectToAction("CreateContract"));
        }