public JsonResult CancProy(int? id, string rason) { ProjectState state = GetEstado(id); if (state.State1.name == "Cancelado") { return Json("0"); } Project p = db.Project.Find(id); foreach (var e in p.ProjectState) { if (e.state) e.state = false; } ProjectState ps = new ProjectState(); ps.state = true; ps.State1 = db.State.Find(4); ps.date = DateTime.Now; ps.description = rason; p.ProjectState.Add(ps); db.SaveChanges(); return Json("1"); }
public ActionResult Create([Bind(Include = "supplementId,number,name,contractId,amount,nom1,nom2,signedClient,productId,serviceId,signedProvider,comitteNumber,comitteDate,expirationDate")] Supplement supplement, int stateC, System.DateTime dateState, string descriptionState, string jsonClient, int contractId, bool idclient) { if (ModelState.IsValid) { supplement.nom1 = "tmpvalue"; supplement.nom2 = "tmpvalue"; StateCSupplement _stateCSupplement = new StateCSupplement { stateCId = stateC, Supplement = supplement, date = dateState, description = descriptionState, state = true }; db.StateCSupplement.Add(_stateCSupplement); List<string> stringData = SetJson(jsonClient); decimal amountValue = 0; if (stringData.Any()) { for (int i = 0; i < stringData.Count(); i += 3) { int id = int.Parse(stringData.ElementAt(i)); string newAmount = stringData.ElementAt(i + 1); string[] newValue = newAmount.Split('.'); decimal endValue = 0; if (newValue.Count() == 2) { decimal decens = decimal.Parse(newValue[0]); decimal centens = decimal.Parse(newValue[1]); endValue = decens + (centens / 100); } else { endValue = decimal.Parse(newAmount); } string idproy = stringData.ElementAt(i + 2); ClientSupplement clientSupplement = new ClientSupplement { clientId = id, Supplement = supplement, amount = endValue }; amountValue += endValue; if (clientSupplement != null) { db.ClientSupplement.Add(clientSupplement); } //creando los proyectos Client client = db.Client.First(c => c.clientId == id); if (client != null) { if (idproy != "*") { Project p = db.Project.Find(int.Parse(idproy)); ProjSup projSup = new ProjSup { Project = p, Supplement = supplement, amount = endValue }; p.totalContracted += endValue; p.toInvoiced += endValue; db.ProjSup.Add(projSup); } else { State c = db.State.Find(3); Project project = new Project { name = supplement.number + " - " + client.name, clientId = id, productId = supplement.productId, advancePercent = 0, totalContracted = endValue, toInvoiced = endValue }; db.Project.Add(project); ProjectState ps = new ProjectState { State1 = c, date = DateTime.Now, description = "Proyecto creado automaticamente al crear Sumpelento", state = true, Project = project }; db.ProjectState.Add(ps); ProjSup projSup = new ProjSup { Project = project, Supplement = supplement, amount = endValue }; db.ProjSup.Add(projSup); } } } } supplement.amount = amountValue; supplement.contractId = contractId; db.Supplement.Add(supplement); db.SaveChanges(); return RedirectToAction("Index", new { id=supplement.contractId, idclient=idclient}); } ViewBag.contractId = contractId; ViewBag.productId = new SelectList(db.Product, "productId", "name", supplement.productId); ViewBag.serviceId = new SelectList(db.Service, "serviceId", "name", supplement.serviceId); ViewBag.stateC = db.StateC.Where(s => s.type == "Suplemento"); Contract contract = db.Contract.First(c => c.contractId == contractId); ViewBag.clientFather = db.Client.First(fa => fa.clientId == contract.clientId); ViewBag.clients = db.Client.Where(cl => cl.fatherId == contract.clientId).ToList(); ViewBag.idclientValue = idclient; return View(supplement); }
//Esatados public JsonResult EnProc(Int32 id) { ProjectState state = GetEstado(id); if (state.State1.name == "EnProceso") { return Json("0"); } Project p = db.Project.Find(id); foreach (var e in p.ProjectState) { if (e.state) e.state = false; } ProjectState ps = new ProjectState(); ps.state = true; ps.State1 = db.State.Find(2); ps.date = DateTime.Now; p.ProjectState.Add(ps); db.SaveChanges(); return Json("1"); }