asp.net mvc - Creating a module for Orchard that stores data from the front-end -


code come later in front of development machine, though hoping in meantime can help....

i trying develop on orchard cms v1.6.1. @ moment in midst of trying develop module allow me place newsletter subscription view within footer (or anywhere else choose) on front end.

i have followed several tutorials , seem show how store data admin - need store data on front end admin... looking on...

so, far, module has "usual" driver/handler/editortemplates view/migrations/contentpart/contentpartrecord , can create subscription entry in admin - have content type setup , see module in admin.

pick tutorial on modules , that's path followed - seem same in terms of creating module , storing data via admin....

with answers other questions managed module display on front-end - way of overriding display in driver , using shapehelper.displaytemplate() method.

some strange things though - when front-end (with form displayed placement.info) page first loads blank entry in database table (subscriptions table) - happens without posting back. have little no idea part of code causing happen. needs not happen - want store data when user fills out form , clicks submit.

secondly, need little guidance in storing data user enters in on front end..

typically should have in module store data entered in front end?

i'm not after actual code - idea of should doing. develop in web forms typically, mvc little new me.

should have controller/route etc?

should form display on front-end separate module have created?

can point me in right direction of store data inside of orchard?

i guess @ point great...

update

thank answers given far. in case use custom forms, though don't want to. ideally want data stored in it's own table.

also, module give me basis need create more complex modules store data front-end. can't seem head around how orchard stitches together.. i.e storing data via controller orchard system..what code need create new row in table?

well, doing in admin creating content type. i'm not sure need storing subscription in such way. maybe don't understand scenario if how wish proceed, may want check out orchard custom forms. admit, unclear how create content types front end. can @ tutorial on how use orchard custom forms. http://devdirective.com/post/160/how-to-create-custom-forms-in-orchard-cms-with-email-and-recaptcha example creating there contact form. pretty simple actually, , powerful. believe included in core. 1.7 @ least.

however, situation newsletter subscription may want different approach, , store list of emails subscribed newsletter in own table.

for need create own widget, part displays form linking own custom controller submits email , saves it. done using simple mvc , want check out tutorials on that.

if users have logged in subscribe newsletter more clever , attach part user , update when want subscribe newsletter. babbling.

i have sort of thrown vague ideas on how go creating own widget display form. i'd happy provide more detail if think route may want go down. else...i'm lazy ^_^

update:

okay, see nick has given pointers on how go this. started reading got bored, think sounds pretty fine though. thought i'd add 2 pennies worth. i'm no expert in orchard how seems me. corrections nonsense appreciated.

parts stitched onto content types. part consists on several parts... see mean.

  • the driver: controller. displays view people see on front end , editor shown when create content item. handles postback when content item created, validation etc.
  • the model: store data part. if have settings related part. inherits gives id connecting content item. cant remember name.
  • the handler: "handles" creation of content item. chuck data repository , can other clever stuff. can drop custom logic services provides. don't worry it, leave stuff.
  • the views: content parts have several views associated them. editor views , display views. these stored in separate folders. editortemplates/parts/... editor stored (shown when create content item). parts/... store views show front end stuff.
  • the placement: file contains information part displayed within content item. pretty cool.

so first thing need create part itself. can write yourself. tedious , easy forget when new. forget important. there vs templates available from... somewhere. use cool little code generation module. go gallery , download , enable code generation extensions piotr szmyd. can run command line application orchard.exe. stored in bin folder within orchard.web. check blog post details on how use module. http://www.szmyd.com.pl/blog/generating-orchard-content-parts-via-command-line

right create part called newsletterpart using command.

codegen part yourmodulename newsletterpart

this generate necessary bits , bobs, drivers etc. part shouldn't need settings. maybe in future when needs simple leave models blank. store list of newsletter subscribers in different table. in bit. first lets display part. there should newsletterpart.cshtml file in views/parts/ folder. write random words in here know displaying. go placement.info file , make sure has line in there tells part displayed. eg:

< place parts_newsletterpart="content:5" />

now need create part , make widget can display part in. done migrations file.

    using system; using orchard.contentmanagement; using orchard.contentmanagement.metadata; using orchard.core.contents.extensions; using orchard.data.migration; using orchard.environment.extensions;  namespace mymodule {     public class migrations : datamigrationimpl {          public migrations() {          }          public int create() {         // create newsletter part table             schemabuilder.createtable("newsletterpartrecord", table => table                 .contentpartrecord()             );          // create part , make attachable content items             contentdefinitionmanager.alterpartdefinition("newsletterpart", builder => builder.attachable());          return 1;     }      public int updatefrom1() {         // create widget         contentdefinitionmanager.altertypedefinition("newsletterwidget", cfg => cfg                 .withpart("newsletterpart")                 .withpart("widgetpart")                 .withpart("commonpart")                 .withsetting("stereotype", "widget"));              return 2;        }     }      } 

you should able create widget on dashboard , appear in footer.

now need create little form display stuff. form this. chuck parts display view instead of whatever wrote before.

@model dynamic  @using (html.beginform("subscribe", "subscription", formmethod.post)) {     <fieldset>         @html.antiforgerytokenorchard()              <label >             email:</label>         @html.textbox("email")<br />           <button class="primaryaction" type="submit">@t("submit")</button>     </fieldset> } 

now lets make model form work. create file in models folder called subscription model following:

using system;  namespace mymodule.models {     public class subscriptionmodel     {         public subscriptionmodel()          {          }          public virtual int id { get; set; }          public virtual string email { get; set; }       } } 

this store email subscribers. need this. can create controller handle everything. create folder called controllers , add file called subscriptioncontroller.cs. add method called subscribe can this:

public class subscriptioncontroller : controller {     private readonly irepository<emailmodel> emailrepository;     public subscriptioncontroller(irepository<emailmodel> emailrepository) {       this.emailrepository = emailrepository;          [httppost]         public actionresult subscribe(string email)         {             var record = new emailrecord() {         email = email         };          this.emailrepository.create(record);               //return return url         }    } } 

all left create emailrecord table in db. migrations , add new method.

public int updatefrom2() {    schemabuilder.createtable("emailmodel", table => table                 .column<string>("email")                 .column<int>("id", column => column.primarykey()));     return 3; } 

just samples wrote in notepad not compile. got bit longer expected...my blunderings.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -