i want create login form control in angularjs. username , password should fetched model class (doctor.cs). using services controller , web api, if authenticated doctor should redirected doctorpanel.cshtml
login.cshtml
<div class="form-group"> <label for="inputemail" class="col-sm-2 control-label">email</label> <div class="col-md-10"> <input type="email" id="email" class="form-control" ng-model="email" required /> </div> </div> <div class="form-group"> <label for="inputpwd" class="col-sm-2 control-label">password</label> <div class="col-md-10"> <input type="text" id="password" class="form-control" ng-model="password" required /> </div> </div> <div class="form-group"> <div class="col-sm-offset-2 col-sm-10"> <button type="submit" class="btn btn-default" ng-click="login()" data-ng-disabled="!formlogin.$valid">login</button> </div> </div> </form> </div>
model class doctor.cs
public class doctor { public int id { get; set; } public string email { get; set; } public string password { get; set; } }
doctorsapicontroller.cs
public class doctorsapicontroller : apicontroller { private digitalhealthwebcontext db = new digitalhealthwebcontext(); // get: api/doctorsapi public list<doctor> getdoctors() { return db.doctors.tolist(); } //public static list<doctor> getdoctors() //{ // var query = doctor in digitalhealthwebcontext.doctors // select doctor; // return db.doctors.tolist(); //} // get: api/doctorsapi/5 [responsetype(typeof(doctor))] public async task<ihttpactionresult> getdoctor(int id) { doctor doctor = await db.doctors.findasync(id); if (doctor == null) { return notfound(); } return ok(doctor); } // put: api/doctorsapi/5 [responsetype(typeof(void))] public async task<ihttpactionresult> putdoctor(int id, doctor doctor) { if (!modelstate.isvalid) { return badrequest(modelstate); } if (id != doctor.id) { return badrequest(); } db.entry(doctor).state = entitystate.modified; try { await db.savechangesasync(); } catch (dbupdateconcurrencyexception) { if (!doctorexists(id)) { return notfound(); } else { throw; } } return statuscode(httpstatuscode.nocontent); } // post: api/doctorsapi [responsetype(typeof(doctor))] public async task<ihttpactionresult> postdoctor(doctor doctor) { if (!modelstate.isvalid) { return badrequest(modelstate); } db.doctors.add(doctor); await db.savechangesasync(); return createdatroute("defaultapi", new { id = doctor.id }, doctor); } // delete: api/doctorsapi/5 [responsetype(typeof(doctor))] public async task<ihttpactionresult> deletedoctor(int id) { doctor doctor = await db.doctors.findasync(id); if (doctor == null) { return notfound(); } db.doctors.remove(doctor); await db.savechangesasync(); return ok(doctor); } protected override void dispose(bool disposing) { if (disposing) { db.dispose(); } base.dispose(disposing); } private bool doctorexists(int id) { return db.doctors.count(e => e.id == id) > 0; } }
i have 3 javascript files namely module.js, service.js, controller.js.
module.js var app = angular.module("docmodule", ["ngroute"]);
//services.js app.service('docservice', function ($http) { this.getdoctors = function () { return $http.get("/api/doctorsapi"); } });
finally controller comes
controller.js
app.controller('doccontroller', function ($scope, docservice) { loadrecords(); function loadrecords() { var promiseget = docservice.getdoctors(); //the method call service promiseget.then(function (pl) { $scope.doctors = pl.data }, function (errorpl) { $log.error('failure loading doctor', errorpl); }); } });
Comments
Post a Comment