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")); }