« first day (2248 days earlier)      last day (2708 days later) » 

12:48 AM
posted on December 11, 2016 by Scott Hanselman

It's a bit of a renaissance out there when it comes to Static Site Generators. There's Jekyll and GitBook, Hugo and Hexo. Middleman and Pelican, Brunch and Octopress. There's dozens, if not hundreds of static site content generators, and "long tail is long." Static Generators a nice for sites that DO get updated with dynamic content, but just not updated every few minutes. That means a Stat

 
 
8 hours later…
8:52 AM
top of the morning to you C#
hope you are all having a wonderful day
 
A day, anyway.
 
Good morning
A c# question
2
A: Validation failed for one or more entities. See 'EntityValidationErrors' property

TommyYour ActionMethod parameters much match exactly the names of the form fields. You are using FName and LName for instance when your actual model properties are FirstName and LastName. As a result, your parameters are empty strings. The model binder has no idea that FName and FirstName are suppo...

I am trying to create an action method which needs to the following
Inserting first name from a textbox, inserting a second name from a text box and inserting a balance
the action method should generates, account number and AppUserId in the checkingaccount table
 
9:14 AM
why did you link the answer though
or not
I'll write a project for you, it'll take me 15 days and 15 nights but I'll be done and email it and it will have this method.
Wait for me.
 
Thank you for your reply. The answer wasn't satisfactory to the answer! Why 15 days!!
lol
@misha130 Is there any way I can reduce the 15 days to 15hrs or perhaps 15 minutes?
:_(
 
well the complications of said project require me to indulge in to many scientific matters
 
All I am asking here for a help with this action method
 
its very complicated
you might have better luck reading the answers ;^)
 
9:30 AM
I did read the answer and it's not working as I am trying to auto generate the AppUserId
I associated a method generates the AppUserId in the AspNetUser table and CheckingAccount tables every time a new user success to register
how do I call this method to my create action method to auto generate the AppUserId
 
why not just set newid() as default in the appuserid in the database
 
The new Id (Primary key)in the AspUserNet table is the AppUserId in the checkingAccount table (Foreign key)
and both are IsIdentity
 
what is the validation error
 
I only insert the first name, last name and the balance text boxes
I auto generate the account number
 
check if the first name/last name are null
"The First Name: field is required.; The Last Name: field is required.; The User ID: field is required." this seems to indicate so
 
9:38 AM
they all required, but I pass the names and the ID is auto generated. They all had values apart of AppUserId
 
debug it, and actually see if there are values in the account service
conveying the first name & last name
 
I will debug now and come to you on here
AppUserId = null
Id = 0
Balance = 200
FirstName = "Chris"
LastName = "Jones"
This is on the debugging
 
and the validation errors are the same?
 
Yup
 
I tried last night. @misha130 I do not seem to be able to convey to @Dodi82 that we need to see the code that generates the form to start with; if it's coming into the create action null then it's not binding properly or it's never set to anything when the form is rendered
 
9:52 AM
I see
I was planning to encourage him to GO DEBUG
but I think I got vamped
 
Morning Tom
It's not a form
You mean a view! right??
 
mvc is a form of sorts
 
this is the create View
@model MVC_ATM.ViewModels.CheckingAccount

@{
    ViewBag.Title = "Create";
}

@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()

    <div class="form-horizontal">
        <h4>Checking Account</h4>
        <hr />
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })

        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        @Html.HiddenFor(model => model.AccountNumber)

        @*<div class="form-group">
            @Html.LabelFor(model => model.AccountNumber, htmlAttributes: new { @class = "control-label col-md-2" })
 
Html.BeginForm
see, form
 
Got it
 
9:56 AM
OK, and what action method calls that view?
 
thanks
        [Authorize(Roles = "Admin")]
        // GET: CheckingAccounts/Create
        public ActionResult Create()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Create(CheckingAccount checkAccount)
        {

            try
            {

                checkAccount.AccountNumber = (12 + db.checkAccounts.Count()).ToString().PadLeft(10, '0');
                db.checkAccounts.Add(checkAccount);
                db.SaveChanges();
                return RedirectToAction("ViewAccounts");
 
NO!
Neither of the return statements bind to that view
 
Why?
 
Oh crap, I didn't see the top one
public ActionResult Create()
        {
            return View();
        }
There. There is no model being passed to the view so I am not surprised all the properties are null
so this: ` @Html.HiddenFor(model => model.AppUserId)` won't have a value
 
the model is CheckingAccount
 
9:59 AM
actually I'd expect it to throw an exception
 
ahaaaaaaaaaaaaaaaaaa
 
I think you need to go away and read more about how MVC works
 
I am learning MVC
and doing my best
 
Actually I would say this design sounds quite insecure. Your Create method accepts whatever it is given, right...so you could change the form's content in the browser and assign a new CheckingAccount to any user you wanted
'hidden' fields just don't show up on the page, you can still edit them in the DOM using the browser dev tools easily
 
This role is only given to Admin and has hidden the View to other users!
 
10:03 AM
But then an Administrator could still do whatever they wanted
just because they're an administrator doesn't mean you trust them
 
so what the best to secure it ?
 
Is AppUserId supposed to represent the logged-in user, or something else?
 
to not write it in the view
 
Its a foreign key to the AppUserNet Table
 
OK, so how does your application determine which user to create an account for? or are you expecting that when you create an account you create a user as well?
 
10:15 AM
Right, I am a new user so I have to register in the website first.
Once I registered (Inserting Names, email and password). The details from the register action method will generate the data in the AppNetUser and the CheckingAccount Tables.
The user Id in the AppNetUser will be deployed in the CheckingAccount.
This is all done when the new user register. Within the CkeckingAccount table the records are: Id - Frist name, last name, account number(auto generated), AppUserId which comes from the AspUserId , and balance with 0 value are all there in the CheckingAccount table
This method is called to the Register action method to create the new user in the CkeckingAccount table
public void CreateAcheckingAccount(string FName, string LName, string UserId, decimal InitialBalance)
            {

                //The account number starts with 0000012 from the beginning of the Checking Account table
                var accountNumber = (12 + Db.checkAccounts.Count()).ToString().PadLeft(10, '0');
                var checking = new CheckingAccount
                {
                    FirstName = FName,
                    LastName = LName,
                    AccountNumber = accountNumber,
It's in the AccountService.cs ViewModel folder
   // GET: /Account/Register
        [AllowAnonymous]
        public ActionResult Register()
        {
            return View();
        }

        //
        // POST: /Account/Register
        [HttpPost]
        [AllowAnonymous]
        [ValidateAntiForgeryToken]
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {

                var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
                var result = await UserManager.CreateAsync(user, model.Password);
And I send the Register action method
 
You said: This method is called to the Register action method to create the new user in the CkeckingAccount table
Where?
I can't see it in that Register method
oh yes I see it, sorry
 
I comment it
in the register
Tom I am going to Morrisons round the corner
do you want anything from there ;-)
 
Cornetto
 
Cool will get it lol
 
sorry that was an obscure joke
 
10:23 AM
it's alright pal
 
The Three Flavours Cornetto trilogy (also known as the Cornetto trilogy or the Blood and Ice Cream trilogy) is a series of British comedic genre films directed by Edgar Wright, written by Wright and Simon Pegg, produced by Nira Park, and starring Pegg and Nick Frost. The trilogy consists of Shaun of the Dead (2004), Hot Fuzz (2007), and The World's End (2013). The name originates from a "silly joke" during the promotion of Hot Fuzz. Wright had written in Cornetto ice cream as a hangover cure for Frost's character in Shaun of the Dead, based on his own experiences. In Hot Fuzz, Wright included a...
 
I think you got a sweet tooth
 
@Tom was ends world actually good?
was it?
I often ponder this
I loved the idea of grabbing a pint from 9 different bars though
 
never seen it
pub crawls are commonplace round here though :D
9 is pushing it
 
10:43 AM
I did 6 once, it was magical
 
Back!
Tom, I hope you got what the previous code does !
The problem is the AppUserId since it will be generated in the AspNetUser table first
 
user6438653
11:09 AM
Anyone wanna play? splix.io/#team-bqBQY
 
user6438653
Because we can.
 
user6438653
 

« first day (2248 days earlier)      last day (2708 days later) »