c# - ASP EF Increment / Decrement Value with + / - buttons -


so i'm new asp , ef , wondering how incredibly basic operation, few questions go along doing it.

currently have table call resource;

class resource {     int current;     int min;     int max; }; 

right have default crud options this. + / - button on main list manipulate current value of each resource , update value in db , on screen.

there operations i'd run such "addfive" selected group of resources.

so questions;

  1. how do this?
  2. is scalable? if hitting buttons going send lot of requests db. there way limit impact of this?
  3. what alternatives?

thanks.

edit: clarify question; here post functions. how / add these in view button showing each resource. want action fire , refresh value rather redirect new page.

@html.actionlink("+", "increment", new { id = item.id })  public void increment(int? id) {     if (id != null)     {         movie movie = db.movies.find(id);         if (movie != null)         {             increment(movie);         }     } }  [httppost, actionname("increment")] [validateantiforgerytoken] public actionresult increment([bind(include = "id,title,releasedate,genre,price")] resource resource) {     if ((resource.current + 1) < (resource.max))         resource.current++;     return view(resource); } 

it sounds main issue having creating list of movies on front end , updating details specific one.

the key here need either wrap form around each item , have posting update controller or use ajax / jquery call controller instead.

i have given example of first one. once update controller hit redirect listing page present updated list of movies.

below minimal working example of how wire up. i've not included data access code brevity have included psuedo code in comments show place it.

please let me know if have futher questions.

controller

public class moviescontroller : controller {     public viewresult index()     {         // data access , mapping of domain vm entities here.          var movielistmodel = new movielistmodel();         return view(movielistmodel);     }      public actionresult increment(incrementmoviecountmodel model)     {         // put breakpoint here , can check value correct         var incrementvalue = model.incrementvalue;         var movieid = model.movieid;          // update movie using entity framework here         // var movie = db.movies.find(id);         // movie.number = movie.number + model.incrementvalue;         // db.movies.save(movie);          // have updated movie can go index list them out incremented number         return redirecttoaction("index");     }  } 

view

@model webapplication1.models.movielistmodel @{     viewbag.title = "index"; }  <h2>some movies</h2>       <table>         <tr>             <td>id</td>             <td>name</td>             <td>increment value</td>             <td></td>         </tr>          @foreach (var movie in model.movielist)         {             using (html.beginform("increment", "movies", formmethod.post))             {                  <tr>                      <td>@movie.id @html.hidden("movieid", movie.id)</td>                      <td>@movie.name</td>                      <td>@html.textbox("incrementvalue", movie.incrementvalue)</td>                      <td><input type="submit" name="update movie"/></td>                  </tr>              }         }     </table> 

models

  public class movielistmodel     {         public movielistmodel()         {             movielist = new list<moviemodel> {new moviemodel{id=1,name = "apocalypse now",incrementvalue = 3}, new moviemodel {id = 2,name = "three lions", incrementvalue = 7} };         }          public list<moviemodel> movielist { get; set; }     }      public class moviemodel     {         public int id { get; set; }         public string name { get; set; }          public int incrementvalue { get; set; }     }      public class incrementmoviecountmodel     {         public int incrementvalue { get; set; }         public int movieid { get; set; }     } 

Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -