Example #1
0
        public ActionResult Create([DataSourceRequest] DataSourceRequest request,CampaignVM viewModel)
        {
            try
            {
                if (viewModel != null && ModelState.IsValid)
                {
                    Campaign newviewModel = new Campaign();

                    newviewModel.EndDate = viewModel.EndDate;
                    newviewModel.Name = viewModel.Name;
                    newviewModel.StartDate = viewModel.StartDate;
                    newviewModel.SystemRuleSystemRuleId = viewModel.SystemId;
                    newviewModel.UserUserId = viewModel.GameMasterId;
                    newviewModel.Description = viewModel.Description;

                    db.Campaigns.Add(newviewModel);
                    db.SaveChanges();
                    viewModel.CampaignId = newviewModel.CampaignId;
                    viewModel.System = db.SystemRules.Find(viewModel.SystemId).SystemName;
                    viewModel.GameMaster = db.Users.Find(viewModel.GameMasterId).Name;
                }
            }
            catch (DataException dataEx)
            {
                ModelState.AddModelError(string.Empty, "Data error");
                Elmah.ErrorSignal.FromCurrentContext().Raise(dataEx);
            }

            return Json(new[] { viewModel }.ToDataSourceResult(request, ModelState));
        }
Example #2
0
 public JsonResult CampaignsListing([DataSourceRequest]DataSourceRequest request, bool AddDefault = false)
 {
     IQueryable<Campaign> tObj = null;
     tObj = db.Campaigns.OrderBy(o => o.Name);
     List<CampaignVM> resultList = new List<CampaignVM>();
     CampaignVM firstItem = new CampaignVM();
     if (AddDefault)
     {
         firstItem.CampaignId = -1;
         firstItem.Name = "None";
         resultList.Add(firstItem);
     }
     foreach (var item in tObj)
     {
         CampaignVM newItem = new CampaignVM();
         newItem.CampaignId = item.CampaignId;
         newItem.Name = item.Name;
         resultList.Add(newItem);
     }
     return Json(resultList, JsonRequestBehavior.AllowGet);
 }
Example #3
0
 public ActionResult Destroy([DataSourceRequest] DataSourceRequest request, CampaignVM viewModel)
 {
     try
     {
         if (viewModel != null)
         {
             ModelState.Clear();
             Campaign delviewModel = db.Campaigns.Find(viewModel.CampaignId);
             if (delviewModel != null)
             {
                 db.Campaigns.Remove(delviewModel);
                 db.SaveChanges();
             }
         }
     }
     catch (DbUpdateException dbUpdEx)
     {
         ModelState.AddModelError("showerror", "Delete failed.  This is most likely due to related child information that needs to be deleted first.");
         Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception("Delete failed.  This is most likely due to related child information that needs to be deleted first."));
         Elmah.ErrorSignal.FromCurrentContext().Raise(dbUpdEx);
     }
     catch (DataException dataEx)
     {
         ModelState.AddModelError("hideerror", "Data error");
         Elmah.ErrorSignal.FromCurrentContext().Raise(dataEx);
     }
     return Json(ModelState.IsValid ? new object() : ModelState.ToDataSourceResult());
 }