Пример #1
0
        //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);
        }