protected override void PerformActionProcess(Controller controller) { ARDataBinder binder = new ARDataBinder(); object instance = binder.BindObject(Model.Type, "", controller.Params); SessionScope scope = new SessionScope(); try { CommonOperationUtils.SaveInstance(instance, controller, errors, prop2Validation); scope.Dispose(); controller.Redirect(controller.AreaName, controller.Name, "list" + Model.Type.Name); } catch (Exception ex) { errors.Add("Could not save " + Model.Type.Name + ". " + ex.Message); scope.Dispose(true); } if (errors.Count != 0) { controller.Context.Flash["errors"] = errors; controller.Redirect(controller.AreaName, controller.Name, "new" + Model.Type.Name); } }
protected BaseAction() { Type = typeof(T); TemplateObjectName = Type.Name.ToLower(); Binder = new ARDataBinder(); PageSize = MRHelper.DefaultPageSize; }
public void CanBindPrimaryKeyToEmptyGuid() { Tag tag = new Tag() { Id = Guid.Empty, Name = "TopMovie" }; tag.Create(); var request = new StubRequest(); request.Params["tag.id"] = Guid.Empty.ToString(); var binder = new ARDataBinder { AutoLoad = AutoLoadBehavior.Always, TreatEmptyGuidAsNull = false}; var record = (Tag)binder.BindObject(typeof(Tag), "tag", request.ParamsNode); Assert.AreEqual(tag.Id, record.Id); }
public void Process() { var filter = (PayerDocumentFilter)BindObject(ParamStore.Form, typeof(PayerDocumentFilter), "filter"); var binder = new ARDataBinder(); binder.AutoLoad = AutoLoadBehavior.Always; SetBinder(binder); var invoices = BindObject <Invoice[]>("invoices"); if (Form["delete"] != null) { foreach (var invoice in invoices) { Mail().InvoiceDeleted(invoice); DbSession.Delete(invoice); } Notify("Удалено"); RedirectToReferrer(); } if (Form["print"] != null) { var printer = Form["printer"]; filter.PrepareFindActInvoiceIds(invoices.Implode(i => i.Id)); var arguments = String.Format("invoice \"{0}\" \"{1}\"", printer, filter.Find <Invoice>(DbSession).Implode(i => i.Id)); Printer.Execute(arguments); Notify("Отправлено на печать"); RedirectToReferrer(); } if (Form["mail"] != null) { foreach (var invoice in invoices) { Mail().InvoiceToEmail(invoice, true); } Notify("Отправлено"); RedirectToReferrer(); } }
public void CanBindPrimaryKeyToEmptyGuid() { var tag = new Tag { Id = Guid.Empty, Name = "TopMovie" }; tag.Create(); var request = new StubRequest(); request.Params["tag.id"] = Guid.Empty.ToString(); var binder = new ARDataBinder { AutoLoad = AutoLoadBehavior.Always, TreatEmptyGuidAsNull = false }; var record = (Tag)binder.BindObject(typeof(Tag), "tag", request.ParamsNode); Assert.AreEqual(tag.Id, record.Id); }
protected override void PerformActionProcess(Controller controller) { ARDataBinder binder = new ARDataBinder(); object idVal = CommonOperationUtils.ReadPkFromParams(controller, ObtainPKProperty()); SessionScope scope = new SessionScope(); try { object instance = SupportingUtils.FindByPK(Model.Type, idVal); binder.BindObjectInstance(instance, String.Empty, controller.Params, null, null); CommonOperationUtils.SaveInstance(instance, controller, errors, prop2Validation); scope.Dispose(); controller.Redirect(controller.AreaName, controller.Name, "list" + Model.Type.Name); } catch (Exception ex) { errors.Add("Could not save " + Model.Type.Name + ". " + ex.Message); scope.Dispose(true); } if (errors.Count != 0) { controller.Context.Flash["errors"] = errors; NameValueCollection parameters = new NameValueCollection(); parameters["id"] = idVal.ToString(); controller.Redirect(controller.AreaName, controller.Name, "edit" + Model.Type.Name, parameters); } }