Exemplo n.º 1
0
 public ActionResult BatchUpdatePartial(MVCxGridViewBatchUpdateValues <GridDataItem, int> batchValues)
 {
     foreach (var item in batchValues.Insert)
     {
         if (batchValues.IsValid(item))
         {
             BatchEditRepository.InsertNewItem(item, batchValues);
         }
         else
         {
             batchValues.SetErrorText(item, "Correct validation errors");
         }
     }
     foreach (var item in batchValues.Update)
     {
         if (batchValues.IsValid(item))
         {
             BatchEditRepository.UpdateItem(item, batchValues);
         }
         else
         {
             batchValues.SetErrorText(item, "Correct validation errors");
         }
     }
     foreach (var itemKey in batchValues.DeleteKeys)
     {
         BatchEditRepository.DeleteItem(itemKey, batchValues);
     }
     return(PartialView("_GridViewPartial", BatchEditRepository.GridData));
 }
Exemplo n.º 2
0
 public ActionResult BatchUpdatePartial(MVCxGridViewBatchUpdateValues <GridDataItem, int> batchValues)
 {
     if (ModelState.IsValid)
     {
         try {
             foreach (var item in batchValues.Insert)
             {
                 if (batchValues.IsValid(item))
                 {
                     BatchEditRepository.InsertNewItem(item);
                 }
             }
             foreach (var item in batchValues.Update)
             {
                 if (batchValues.IsValid(item))
                 {
                     BatchEditRepository.UpdateItem(item);
                 }
             }
             foreach (var itemKey in batchValues.DeleteKeys)
             {
                 BatchEditRepository.DeleteItem(itemKey);
             }
         } catch (Exception e) {
             ViewData["EditError"] = e.Message;
         }
     }
     else
     {
         ViewData["EditError"] = "Please, correct all errors.";
     }
     return(PartialView("_GridViewPartial", BatchEditRepository.GridData));
 }
        /* save all changes to a data base in this action */
        public bool UpdateAllValues(MVCxGridViewBatchUpdateValues <GridDataItem, int> batchValues, MainModel mainModel)
        {
            if (batchValues != null)
            {
                foreach (var item in batchValues.Insert)
                {
                    if (batchValues.IsValid(item))
                    {
                        BatchEditRepository.InsertNewItem(item, batchValues);
                    }
                    else
                    {
                        batchValues.SetErrorText(item, "Correct validation errors");
                    }
                }
                foreach (var item in batchValues.Update)
                {
                    if (batchValues.IsValid(item))
                    {
                        BatchEditRepository.UpdateItem(item, batchValues);
                    }
                    else
                    {
                        batchValues.SetErrorText(item, "Correct validation errors");
                    }
                }
                foreach (var itemKey in batchValues.DeleteKeys)
                {
                    BatchEditRepository.DeleteItem(itemKey, batchValues);
                }
            }
            bool result = false;

            if (mainModel != null)
            {
                //custom actions
                result = true;
            }
            return(result && (batchValues == null || batchValues.EditorErrors.Count == 0));
        }