Ejemplo n.º 1
0
        public ActionResult EditChild(int id = 0)
        {
            SubDocumentEditViewModel model = new SubDocumentEditViewModel();

            model.document = db.Documents.Include(d => d.Rules).FirstOrDefault(d => d.ID == id);
            return(View(model));
        }
Ejemplo n.º 2
0
        public ActionResult CreateChild(SubDocumentEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                Document parent = db.Documents.Include(d => d.Rules)
                                  .Include(d => d.Document1).Include(d => d.Document2)
                                  .FirstOrDefault(d => d.ID == model.document.documentParentID);
                model.document.documentTypeID = parent.documentTypeID;
                model.document.companyID      = parent.companyID;
                Helper.updateObjectFields(model.document);
                double edt = 0;
                if (parent.Document1.Count() > 0)
                {
                    edt = (from d in parent.Document1
                           select d.EDT).Max();
                }
                model.document.EDT = edt + 1;

                db.Documents.Add(model.document);
                db.SaveChanges();

                if (parent.Document2 != null)
                {
                    return(RedirectToAction("EditChild", new { id = parent.ID }));
                }
                else
                {
                    return(RedirectToAction("Edit", new { id = parent.ID }));
                }
            }

            return(View(model));
        }
Ejemplo n.º 3
0
        public ActionResult EditChild(SubDocumentEditViewModel model, string submitVal)
        {
            if (ModelState.IsValid)
            {
                model.document.updateDate = DateTime.Now;
                Helper.updateObjectFields(model.document);
                model.document.Rules.Clear();
                db.Entry(model.document).State = EntityState.Modified;
                db.SaveChanges();

                Document document = db.Documents.Include(d => d.Rules)
                                    .FirstOrDefault(d => d.ID == model.document.ID);
                document.Rules.Clear();
                db.SaveChanges();

                //if (model.selectedRules != null)
                //    foreach (int ruleId in model.selectedRules)
                //    {
                //        document.Rules.Add(db.Rules.Find(ruleId));
                //    }

                db.Entry(document).State = EntityState.Modified;
                db.SaveChanges();
                if (submitVal == "Capitulo")
                {
                    return(RedirectToAction("CreateChild", new { id = model.document.ID }));
                }
                else
                {
                    if (db.Documents.Include(d => d.Document2)
                        .FirstOrDefault(d => d.ID == model.document.documentParentID)
                        .Document2 == null)
                    {
                        return(RedirectToAction("Edit", new { id = model.document.documentParentID }));
                    }
                    return(RedirectToAction("EditChild", new { id = model.document.documentParentID }));
                }
            }

            model.document.documentTypeID = (from d in db.DocumentTypes
                                             where d.name == "Politica"
                                             select d.ID).FirstOrDefault();

            ViewBag.allRules = Helper.GetRulesSelect(db);

            return(View(model));
        }
Ejemplo n.º 4
0
        public ActionResult CreateChild(int id = 0)
        {
            Document parent = db.Documents.Include(d => d.Rules)
                              .FirstOrDefault(d => d.ID == id);

            if (parent == null)
            {
                return(HttpNotFound());
            }
            SubDocumentEditViewModel model = new SubDocumentEditViewModel();

            model.document.Document2        = parent;
            model.document.documentParentID = id;
            model.document.documentTypeID   = parent.documentTypeID;

            return(View(model));
        }
Ejemplo n.º 5
0
        public ActionResult CreateChild(int id = 0)
        {
            Document parent = db.Documents.Find(id);

            if (parent == null)
            {
                return(HttpNotFound());
            }
            SubDocumentEditViewModel model = new SubDocumentEditViewModel();

            model.document.Document2        = parent;
            model.document.companyID        = parent.companyID;
            model.document.documentTypeID   = parent.documentTypeID;
            model.document.documentParentID = id;

            return(View(model));
        }
Ejemplo n.º 6
0
        public ActionResult EditChild(SubDocumentEditViewModel model, string submitVal)
        {
            if (ModelState.IsValid)
            {
                model.document.updateDate = DateTime.Now;
                model.document.companyID  = (int)db.Users.Find(WebSecurity.CurrentUserId).companyID;
                Helper.updateObjectFields(model.document);
                model.document.Rules.Clear();
                db.Entry(model.document).State = EntityState.Modified;
                db.SaveChanges();

                Document document = db.Documents.Include(d => d.Rules)
                                    .FirstOrDefault(d => d.ID == model.document.ID);
                document.Rules.Clear();
                db.SaveChanges();

                db.Entry(document).State = EntityState.Modified;
                db.SaveChanges();
                if (submitVal == "Capitulo")
                {
                    return(RedirectToAction("CreateChild", new { id = model.document.ID }));
                }
                else
                {
                    if (db.Documents.Include(d => d.Document2)
                        .FirstOrDefault(d => d.ID == model.document.documentParentID)
                        .Document2 == null)
                    {
                        return(RedirectToAction("Edit", new { id = model.document.documentParentID }));
                    }
                    return(RedirectToAction("EditChild", new { id = model.document.documentParentID }));
                }
            }

            model.document.documentTypeID = (from d in db.DocumentTypes
                                             where d.name == "Manual"
                                             select d.ID).FirstOrDefault();

            ViewBag.allRules = Helper.GetRulesSelect(db);

            return(View(model));
        }