Esempio n. 1
0
        public ActionResult Create([Bind(Include = "contractId,number,signedProvider,nom1,nom2,description,clientId,expirationDate,signedClient,comitteNumber,comitteDate")] Contract contract, int stateC, System.DateTime dateState, string descriptionState, int idClient)
        {
            if (ModelState.IsValid)
            {
                StateContract _stateContract = new StateContract
                {
                    stateCId = stateC,
                    Contract = contract,
                    date = dateState,
                    description = descriptionState,
                    state = true
                };
                db.StateContract.Add(_stateContract);
                contract.nom1 = "tempvalue";
                contract.nom2 = "tmpvalue";
                contract.clientId = idClient;
                db.Contract.Add(contract);
                db.SaveChanges();
                return RedirectToAction("Index", new { id = contract.clientId });
            }

            ViewBag.clientId = contract.clientId;
            ViewBag.stateC = db.StateC.Where(s => s.type == "Contrato");
            //ViewBag.clientId = new SelectList(db.Client, "clientId", "name", contract.clientId);
            return View(contract);
        }
Esempio n. 2
0
        public ActionResult DeleteConfirmed(int id,string descriptionState)
        {
            Contract contract = db.Contract.Find(id);
            List<StateContract> stateContracts = db.StateContract.Where(s => s.contractId == contract.contractId).ToList();
            bool found = false;
            foreach (StateContract stateContract in stateContracts)
            {
                stateContract.state = false;
            }

                StateContract _stateContract = new StateContract
                {
                    stateCId = 9,
                    Contract = contract,
                    date = DateTime.Now,
                    description = descriptionState,
                    state = true
                };
                db.StateContract.Add(_stateContract);

            db.SaveChanges();
            return RedirectToAction("Index");
        }
Esempio n. 3
0
        public ActionResult Edit([Bind(Include = "contractId,number,signedProvider,nom1,nom2,description,clientId,expirationDate,signedClient,comitteNumber,comitteDate")] Contract contract, int stateC, System.DateTime dateState, string descriptionState, int idClient)
        {
            if (ModelState.IsValid)
            {
                List<StateContract> stateContracts = db.StateContract.Where(s => s.contractId == contract.contractId).ToList();
                bool found = false;
                foreach (StateContract stateContract in stateContracts)
                {
                    if (stateContract.stateCId == stateC)
                    {
                        found = true;
                        stateContract.state = true;
                        stateContract.date = dateState;
                        stateContract.description = descriptionState;
                    }
                    else
                    {
                        stateContract.state = false;
                    }
                }
                if (!found)
                {
                    StateContract _stateContract = new StateContract
                    {
                        stateCId = stateC,
                        Contract = contract,
                        date = dateState,
                        description = descriptionState,
                        state = true
                    };
                    db.StateContract.Add(_stateContract);
                }
                //db.SaveChanges();

                contract.clientId = idClient;
                db.Entry(contract).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index","ClientContract",new {id=idClient});
            }
            ViewBag.clientId = new SelectList(db.Client, "clientId", "name", contract.clientId);
            return View(contract);
        }