Exemple #1
0
        //*********************************************************************************************************************************
        // GET: Contract/Create/CreateGeneral
        public ActionResult CreateGeneral(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            //David Create and populate the ViewModel
            var model = new ContractCreateGeneralViewModel();

            //Set the Contract Id !!before initialization with Helper
            model.ContractId = (int)id;
            model            = CreateGeneralHelper(model);

            return(View(model));
        }
        public ActionResult CreateGeneral(ContractCreateGeneralViewModel generalViewModel)
        {
            //load contract from db
            var contract = db.Contracts.Find(generalViewModel.ContractId);

            //load the cKind and set it
            var cKind = db.ContractKinds.Find(generalViewModel.ContractsKindId);

            contract.ContractKind = cKind;

            //load the cType and set it
            var cType = db.ContractTypes.Find(generalViewModel.ContractsTypeId);

            contract.ContractType = cType;

            //FrameContract
            FrameContract frame;

            switch (generalViewModel.FrameOptionChosen)
            {
            case "FrameMain":
                frame = new FrameContract();
                frame.MainContract       = contract;
                contract.IsFrameContract = true;
                db.FrameContracts.Add(frame);
                break;

            case "FrameSub":
                var fMain = db.FrameContracts.Find(generalViewModel.MainFrameIdSelected);
                frame = (FrameContract)fMain;
                frame.Contracts.Add(contract);
                contract.FrameContract = frame;
                db.Entry(frame).State  = EntityState.Modified;
                break;

            case "NoFrame":
            default:
                break;
            }

            db.Entry(contract).State = EntityState.Modified;
            db.SaveChanges();

            return(RedirectToAction("CreateDates", new { id = contract.Id }));
        }
        public ActionResult CreateGeneral(ContractCreateGeneralViewModel generalViewModel)
        {
            //load contract from db
            var contract = db.Contracts.Find(generalViewModel.ContractId);

            //load the cKind and set it
            var cKind = db.ContractKinds.Find(generalViewModel.ContractsKindId);

            contract.ContractKind = cKind;

            //load the cType and set it
            var cType = db.ContractTypes.Find(generalViewModel.ContractsTypeId);

            contract.ContractType = cType;

            db.Entry(contract).State = EntityState.Modified;
            db.SaveChanges();

            return(RedirectToAction("CreateDates", new { id = contract.Id }));
        }
        // GET: Contract/Create/CreateGeneral
        public ActionResult CreateGeneral(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            //David Create and populate the ViewModel
            var generalViewModel = new ContractCreateGeneralViewModel();

            //Set the Contract Id
            var contract = db.Contracts.Find(id);

            generalViewModel.ContractId = contract.Id;

            //Set the types and kinds
            generalViewModel.ContractKinds = new SelectList(db.ContractKinds, "Id", "Description");
            generalViewModel.ContractTypes = new SelectList(db.ContractTypes, "Id", "Description");

            return(View(generalViewModel));
        }
        // GET: Contract/Create/CreateGeneral
        public ActionResult CreateGeneral(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            //David Create and populate the ViewModel
            var generalViewModel = new ContractCreateGeneralViewModel();

            //Set the Contract Id
            var contract = db.Contracts.Find(id);

            generalViewModel.ContractId = contract.Id;

            //Set the types and kinds
            generalViewModel.ContractKinds = new SelectList(db.ContractKinds, "Id", "Description");
            generalViewModel.ContractTypes = new SelectList(db.ContractTypes, "Id", "Description");

            //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"
            });
            generalViewModel.FrameContractChoice = frameContractChoice;



            return(View(generalViewModel));
        }
Exemple #6
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);
        }
Exemple #7
0
        public ActionResult CreateGeneral(ContractCreateGeneralViewModel model, string submit)
        {
            if (ModelState.IsValid) //If all values are accepted
            {
                //load contract
                var contract = db.Contracts.Find(model.ContractId);

                //set contract from model
                db.Entry(contract).Reference(c => c.ContractKind).Load(); //Must loaded before setting to null
                contract.ContractKind = db.ContractKinds.Find(model.ContractKindId);
                db.Entry(contract).Reference(c => c.ContractType).Load();
                contract.ContractType = db.ContractTypes.Find(model.ContractTypeId);
                db.Entry(contract).Reference(c => c.ContractSubType).Load();
                contract.ContractSubType        = db.ContractSubTypes.Find(model.ContractSubTypeId);
                contract.DepartmentId           = model.DepartmentId;
                contract.SupervisorDepartmentId = model.SupervisorDepartmentId;
                contract.Remarks = model.Remarks;
                var docAdress = new PhysicalDocAddress();
                docAdress.Department        = db.Departments.Find(model.PDA_DepartmentId);
                docAdress.Room              = model.PDA_Room;
                docAdress.Address           = model.PDA_Adress;
                contract.PhysicalDocAddress = docAdress;
                db.Entry(contract).Reference(c => c.ContractPartner).Load();
                contract.ContractPartner = db.ContractPartners.Find(model.ContractPartnerId);
                contract.ExtContractNum  = model.ExtContractNum;

                //FrameContract
                switch (model.FrameOptionChosen)
                {
                case "FrameMain":
                    contract.IsFrameContract = true;
                    break;

                case "FrameSub":
                    /*contract.IsFrameContract = false;*/
                    if (model.MainFrameIdSelected != null)
                    {
                        var frame = db.Contracts.Find(model.MainFrameIdSelected);
                        contract.FrameContract = frame;
                    }
                    break;

                //case "NoFrame":
                default:
                    contract.IsFrameContract = false;
                    contract.FrameContractId = null;
                    break;
                }

                //Set Contract Status
                contract.ContractStatus = HelperUtility.checkContractStatus(contract, db);

                db.Entry(contract).State = EntityState.Modified;
                db.SaveChanges();

                //Decide which button was pressed...then redirect
                if (submit == continueBtn)
                {
                    return(RedirectToAction("CreateDates", new { id = contract.Id }));
                }
                else
                {
                    return(RedirectToAction("Index"));
                }
            }

            //Repeat Model Initialization of SelectLists -> See GET: ActionMethod
            model = CreateGeneralHelper(model);
            //initialization:end

            return(View(model));
        }