//Helpers public ActionResult GetJsonUsersFromClient(string client) { var departments = QueryUtility.GetDepartmentsFromClient(client, db); IEnumerable <ContractUser> users = Enumerable.Empty <ContractUser>(); //users.Concat(new[] { manager.FindByName("Admin") }); foreach (Department d in departments) { if (d.DepartmentName != null) { IEnumerable <ContractUser> addUser = QueryUtility.GetUsersFromDepartment(d.DepartmentName, db).AsEnumerable <ContractUser>(); if (addUser.Any()) { users = users.Concat(addUser); } } } //IQueryable<ContractUser> test = QueryUtility.GetUsersFromDepartment(departments.FirstOrDefault().DepartmentName, db); List <SelectListItem> data = new SelectList(users, "Id", "UserName").ToList(); return(Json(data)); }
//CreateGeneralHelper public ContractCreateGeneralViewModel CreateGeneralHelper(ContractCreateGeneralViewModel model) { Contract contract = db.Contracts.Find(model.ContractId); if (contract != null) { //Fill model with Data from Reload-Model or from current contract, if Reload-Model is empty model.ContractKindId = (model.ContractKindId != null) ? model.ContractKindId : ((contract.ContractKind != null) ? (int?)contract.ContractKind.Id : null); model.ContractTypeId = (model.ContractTypeId != null) ? model.ContractTypeId : ((contract.ContractType != null) ? (int?)contract.ContractType.Id : null); model.ContractSubTypeId = (model.ContractSubTypeId != null) ? model.ContractSubTypeId : ((contract.ContractSubType != null) ? (int?)contract.ContractSubType.Id : null); model.DepartmentId = (model.DepartmentId != null) ? model.DepartmentId : ((contract.Department != null) ? (int?)contract.Department.Id : null); model.DepartmentId = (model.SupervisorDepartmentId != null) ? model.SupervisorDepartmentId : ((contract.SupervisorDepartment != null) ? (int?)contract.SupervisorDepartment.Id : null); model.Remarks = (model.Remarks != null) ? model.Remarks : contract.Remarks; model.ExtContractNum = (model.ExtContractNum != null) ? model.ExtContractNum : contract.ExtContractNum; // If Contract is FrameContract if (contract.IsFrameContract == true) { model.FrameOptionChosen = "FrameMain"; } else { //If Contract is Subcontract if (contract.FrameContract != null) { model.MainFrameIdSelected = contract.FrameContract.Id; model.FrameOptionChosen = "FrameSub"; } } //If a new DocAdress was given if (model.PhysicalDocAdressId == 0) { if (contract.PhysicalDocAddress != null) { model.PhysicalDocAdressId = contract.PhysicalDocAddress.Id; model.PDA_Adress = contract.PhysicalDocAddress.Address; model.PDA_DepartmentId = contract.PhysicalDocAddress.Department.Id; } } model.ContractPartnerId = (model.ContractPartnerId != 0) ? model.ContractPartnerId : ((contract.ContractPartner != null) ? (int?)contract.ContractPartner.Id : null); } var userId = User.Identity.GetUserId(); var currentUser = manager.FindById(userId); //Set the types and kinds model.ContractKinds = new SelectList(db.ContractKinds, "Id", "Description", model.ContractKindId); model.ContractTypes = new SelectList(db.ContractTypes, "Id", "Description", model.ContractTypeId); model.ContractSubTypes = new SelectList(db.ContractSubTypes, "Id", "Description", model.ContractSubTypeId); model.ContractPartners = new SelectList(db.ContractPartners, "Id", "Name", model.ContractPartnerId); //Gets Department of inlogged User var currentDepartment = QueryUtility.GetDepartmentsOfUser(currentUser.UserName, db); //Get Client of first Department var currentClient = QueryUtility.GetClientOfDepartment(currentDepartment.Select(d => d.DepartmentName).FirstOrDefault(), db); //Get all Departments from Client var DepartmentsFromClient = QueryUtility.GetDepartmentsFromClient(currentClient.Select(d => d.ClientName).FirstOrDefault(), db); //Init and set Department of inlogged User as Default value //Doesn't work now with default value; if (DepartmentsFromClient.Any()) { model.Departments = new SelectList(DepartmentsFromClient, "Id", "DepartmentName", currentDepartment.FirstOrDefault().Id); } else { model.Departments = new SelectList(new[] { "No Departments found" }); } //Christoph: set up the Dropdownlist for FrameContractChoice: List <SelectListItem> frameContractChoice = new List <SelectListItem>(); frameContractChoice.Add(new SelectListItem { Text = "Kein Rahmenvertrag", Value = "NoFrame", Selected = true }); frameContractChoice.Add(new SelectListItem { Text = "Ist Hauptvertrag", Value = "FrameMain" }); frameContractChoice.Add(new SelectListItem { Text = "Ist Untervertrag", Value = "FrameSub" }); model.FrameContractChoice = frameContractChoice; var frameContracts = QueryUtility.GetFrameContractsOfUser(currentUser.UserName, db); model.MainFrameContracts = new SelectList(frameContracts, "Id", "Description", "---Select framecontract---"); //Add Contract to View to display its information in following Forms (like Status and Name) model.Contract = contract; return(model); }
public ActionResult GetJsonDepartmentsFromClient(string client) { var data = new SelectList(QueryUtility.GetDepartmentsFromClient(client, db), "Id", "DepartmentName").ToList(); return(Json(data)); }
//CreateInitHelper public ContractCreateInitViewModel CreateInitHelper(ContractCreateInitViewModel model) { //Get User for SelectLists later var userId = User.Identity.GetUserId(); var currentUser = manager.FindById(userId); string currentName = currentUser.UserName.ToString(); //If Contract already exists if (model.ContractId != null) { Contract contract = db.Contracts.Find(model.ContractId); if (contract != null) { //set required attributes model.OwnerId = contract.OwnerId; model.Description = contract.Description; model.SignerName = contract.Signer.UserName; } } else { //set Signer to current User model.SignerName = currentUser.UserName; //Put default value for Owner in the form model.OwnerId = userId; } //Get SelectLists for Dropdown initialize with default User model.OwnerList = new SelectList(new[] { manager.FindById(userId) }, "Id", "UserName", model.OwnerId); //Initializes the ClientList with all existent Clients model.ClientList = new SelectList(db.Clients, "Id", "ClientName"); //Get Department from User Department currentDepartment = QueryUtility.GetDepartmentsOfUser(currentName, db).FirstOrDefault(); //Get Client off the current User for the signer-Dropdown string currentClientName; if (currentDepartment != null) { //Saves the Client of Department of current User in currentClient IQueryable <Client> currentClient = QueryUtility.GetClientOfDepartment(currentDepartment.DepartmentName, db); currentClientName = currentClient.Select(c => c.ClientName).FirstOrDefault(); if (currentClientName == null) { currentClientName = model.ClientList.FirstOrDefault().Text; } } else { //this case is only relevent for Users without a department (should only be the Admin) currentClientName = model.ClientList.FirstOrDefault().Text; currentDepartment = db.Departments.FirstOrDefault(); } //Get the Department from the clients for the Owner-DropDown model.DepartmentList = new SelectList(QueryUtility.GetDepartmentsFromClient(currentClientName, db), "Id", "DepartmentName", currentDepartment.Id); return(model); }