public ActionResult Create([DataSourceRequest] DataSourceRequest request, ReqDocCandidate reqDocCandidate)
        {
            if (reqDocCandidate != null && ModelState.IsValid)
            {
                db.ReqDocCandidate.Add(reqDocCandidate);
                db.SaveChanges();
            }

            return Json(new[] { reqDocCandidate }.ToDataSourceResult(request, ModelState));
        }
 public ActionResult Update([DataSourceRequest]DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<ReqDocCandidateViewModel> reqDocCandidate)
 {
     // Will keep the updated entitites here. Used to return the result later.
     var entities = new List<ReqDocCandidate>();
     if (ModelState.IsValid)
     {
         //using (var northwind = new NorthwindEntities())
         //{
         foreach (var d in reqDocCandidate)
         {
             // Create a new Product entity and set its properties from the posted ProductViewModel
             var entity = new ReqDocCandidate
             {
                 Id = d.Id,
                 CandidateId = d.CandidateId,
                 ReqDocumentId = d.ReqDocumentId,
                 DocumentNumber = d.DocumentNumber,
                 IssueDate = d.IssueDate,
                 ValidTo = d.ValidTo,
                 Note = d.Note
             };
             // Store the entity for later use
             entities.Add(entity);
             // Attach the entity
             db.ReqDocCandidate.Attach(entity);
             // Change its state to Modified so Entity Framework can update the existing product instead of creating a new one
             db.Entry(entity).State = EntityState.Modified;
             // Or use ObjectStateManager if using a previous version of Entity Framework
             // northwind.ObjectStateManager.ChangeObjectState(entity, EntityState.Modified);
         }
         // Update the entities in the database
         db.SaveChanges();
         //}
     }
     // Return the updated entities. Also return any validation errors.
     return Json(reqDocCandidate.ToDataSourceResult(request, ModelState));
 }
        public ActionResult Destroy([DataSourceRequest] DataSourceRequest request, ReqDocCandidate reqDocCandidate)
        {
            if (reqDocCandidate != null)
            {
                db.ReqDocCandidate.Remove(reqDocCandidate);
                db.SaveChanges();
            }

            return Json(new[] { reqDocCandidate }.ToDataSourceResult(request, ModelState));
        }
Пример #4
0
 public ActionResult ReqDoc_Update([DataSourceRequest]DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<ReqDocCandidateViewModel> reqDocCandidate)
 {
     var entities = new List<ReqDocCandidate>();
     if (ModelState.IsValid)
     {
         foreach (var d in reqDocCandidate)
         {
             var entity = new ReqDocCandidate
             {
                 Id = d.Id,
                 CandidateId = d.CandidateId,
                 ReqDocumentId = d.ReqDocumentId,
                 DocumentNumber = d.DocumentNumber,
                 IssueDate = d.IssueDate,
                 ValidTo = d.ValidTo,
                 Note = d.Note
             };
             entities.Add(entity);
             db.ReqDocCandidate.Attach(entity);
             db.Entry(entity).State = EntityState.Modified;
         }
         db.SaveChanges();
     }
     return Json(reqDocCandidate.ToDataSourceResult(request, ModelState));
 }