//GET
        public ActionResult CreateInit()
        {
            var initViewModel = new ContractCreateInitViewModel();

            var currentUser = manager.FindById(User.Identity.GetUserId());

            string currentName   = currentUser.UserName.ToString();
            string currentUserId = currentUser.Id.ToString();

            ViewBag.OwnerName = currentUserId;

            string currentDepartmentName = UtilAugust.GetDepartmentsOfUser(currentName, db).Select(d => d.DepartmentName).FirstOrDefault();

            ViewBag.ClientSelect = new SelectList(db.Mandants, "Id", "MandantName");

            IQueryable <Mandant> currentClient = UtilAugust.GetClientOfDepartment(currentDepartmentName, db);
            string currentClientName           = currentClient.Select(c => c.MandantName).FirstOrDefault();

            ViewBag.CoordinatorId = new SelectList(UtilAugust.GetCoordinatorsFromClient(currentClientName, db), "Id", "UserName");
            ViewBag.ClientId      = new SelectList(db.Mandants, "Id", "MandantName");

            initViewModel.Coordinators = new SelectList(UtilAugust.GetCoordinatorsFromClient(currentClientName, db), "Id", "UserName");

            return(View(initViewModel));
        }
Example #2
0
        public ActionResult CreateInit(ContractCreateInitViewModel model, string submit)
        {
            if (ModelState.IsValid)
            {
                //Initialize new contract
                Contract contract = new Contract();
                if (model.ContractId != null)
                {
                    //this only if contract is edited - load contract from db
                    var c = db.Contracts.Find(model.ContractId);
                    if (c != null)
                    {
                        contract = c;
                    }
                }
                else
                {
                    //first creation of the contract - Signer and owner are not to be changed
                    contract.SignerId = User.Identity.GetUserId();
                    contract.OwnerId  = model.OwnerId;
                }

                contract.Description = model.Description;

                //Set Contract Status
                contract.ContractStatus = HelperUtility.checkContractStatus(contract, db);
                //Add Contract to View to display its information in the RightFormPartial (for Status etc...)
                model.Contract = contract;

                if (contract.Id == 0) //Means that contract isn't in DB
                {
                    db.Contracts.Add(contract);
                }
                else
                {
                    db.Entry(contract).State = EntityState.Modified;
                }
                db.SaveChanges();

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

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

            return(View(model));
        }
Example #3
0
        //*********************************************************************************************************************************
        //GET: CreateInit
        public ActionResult CreateInit(int?id)
        {
            //id is required when in Edit mode
            ContractCreateInitViewModel model = new ContractCreateInitViewModel();

            if (id != null)
            {
                model.ContractId = (int)id;
            }
            model = CreateInitHelper(model);
            return(View(model));
        }
        public ActionResult CreateInit(ContractCreateInitViewModel initViewModel)
        {
            var Owner       = db.Users.Find(initViewModel.OwnerId);
            var Coordinator = db.Users.Find(initViewModel.CoordinatorId);

            var contract = new Contract();

            contract.ContractOwner = Owner;
            contract.Coordinator   = Coordinator;

            contract.Description = initViewModel.Description;

            db.Contracts.Add(contract);
            db.SaveChanges();
            return(RedirectToAction("CreateGeneral", new { id = contract.Id }));
        }
Example #5
0
        //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);
        }