public HttpResponseMessage Delete(int id) { try { using (PracticeEntities entities = new PracticeEntities()) { var entity = entities.Employees.FirstOrDefault(emp => emp.employee_id == id); if (entity != null) { entities.Employees.Remove(entity); entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } else { return(Request.CreateResponse(HttpStatusCode.NotFound, "Employee with id" + id.ToString() + "not found")); } } } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.BadRequest, ex)); } }
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) { //context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" }); User user = new User(); using (PracticeEntities _dbContext = new PracticeEntities()) { user = _dbContext.Users.Where(x => x.UserName == context.UserName && x.PassWord == context.Password).FirstOrDefault(); if (user == null) { context.SetError("invalid_grant", "The user name or password is incorrect."); return; } } var identity = new ClaimsIdentity(context.Options.AuthenticationType); if (user.Role == "Admin") { identity.AddClaim(new Claim(ClaimTypes.Role, "admin")); identity.AddClaim(new Claim("username", "admin")); identity.AddClaim(new Claim(ClaimTypes.Name, "Vinod Pal")); context.Validated(identity); } else if (user.Role == "User") { identity.AddClaim(new Claim(ClaimTypes.Role, "user")); identity.AddClaim(new Claim("username", "user")); identity.AddClaim(new Claim(ClaimTypes.Name, "Vivek Kuamr")); context.Validated(identity); } }
public HttpResponseMessage Put(int id, [FromBody] Employee employee) { try { using (PracticeEntities entities = new PracticeEntities()) { var entity = entities.Employees.FirstOrDefault(emp => emp.employee_id == id); if (entity != null) { entity.months = employee.months; entity.name = employee.name; entity.salary = employee.salary; entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } else { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Employee with id" + id.ToString() + "not found")); } } } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.BadRequest, ex)); } }
public ActionResult Edit(string key) { PracticeEntities practiceEntities = new PracticeEntities(); var result = practiceEntities.Members.Where(x => x.Account == key).ToList(); return(View(result)); }
public AuthorInfo Get(int id) { using (PracticeEntities x = new PracticeEntities()) { return(x.AuthorInfoes.FirstOrDefault(e => e.AID == id)); } }
// PUT: api/author/5 public HttpResponseMessage Put(int id, AuthorInfo b) { try { using (PracticeEntities x = new PracticeEntities()) { var y = x.AuthorInfoes.FirstOrDefault(e => e.AID == id); if (y == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Author with Id=" + id.ToString() + " not found")); } else { y.AuthorName = b.AuthorName; y.City = b.City; x.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, y)); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public ActionResult Contact() { PracticeEntities practiceEntities = new PracticeEntities(); var result = practiceEntities.Members.ToList(); return(View(result)); }
public BookInfo Get(int id) { using (PracticeEntities x = new PracticeEntities()) { return(x.BookInfoes.FirstOrDefault(e => e.ID == id)); } }
public ActionResult Edit(int?ID) { if (ID == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } using (PracticeEntities _context = new PracticeEntities()) { Contact contact = (from c in _context.Contacts where c.Id == ID select c).FirstOrDefault(); if (contact == null) { return(HttpNotFound()); } return(View(contact)); } //try //{ // using (PracticeEntities _context = new PracticeEntities()) // { // var contact = (from c in _context.Contacts // where c.Id == ID // select c).FirstOrDefault(); // return View(contact); // } //} //catch (Exception) //{ // throw; //} }
public ActionResult GetContactsServersidePagingSorting() { var draw = Request.Form.GetValues("draw").FirstOrDefault(); var start = Request.Form.GetValues("start").FirstOrDefault(); var length = Request.Form.GetValues("length").FirstOrDefault(); //Find Order Column var sortColumn = Request.Form.GetValues("columns[" + Request.Form.GetValues("order[0][column]").FirstOrDefault() + "][name]").FirstOrDefault(); var sortColumnDir = Request.Form.GetValues("order[0][dir]").FirstOrDefault(); int pageSize = length != null?Convert.ToInt32(length) : 0; int skip = start != null?Convert.ToInt32(start) : 0; int recordsTotal = 0; using (PracticeEntities db = new PracticeEntities()) { // dc.Configuration.LazyLoadingEnabled = false; // if your table is relational, contain foreign key var v = (from a in db.Contacts select a); //SORT if (!(string.IsNullOrEmpty(sortColumn) && string.IsNullOrEmpty(sortColumnDir))) { v = v.OrderBy(sortColumn + " " + sortColumnDir); } recordsTotal = v.Count(); var data = v.Skip(skip).Take(pageSize).ToList(); return(Json(new { draw = Convert.ToInt32(draw), recordsFiltered = recordsTotal, recordsTotal = recordsTotal, data = data }, JsonRequestBehavior.AllowGet)); } }
public IEnumerable <AuthorInfo> authordetails() { using (PracticeEntities x = new PracticeEntities()) { return(x.AuthorInfoes.ToList()); } }
public IEnumerable <BookInfo> bookslist() { using (PracticeEntities x = new PracticeEntities()) { return(x.BookInfoes.ToList()); } }
// GET: DataTables Server side pagination, sorting, filtering and crud //public ActionResult Index4() //{ // return View(); //} public ActionResult GetContacts() { using (PracticeEntities db = new PracticeEntities()) { var contacts = db.Contacts.ToList(); return(Json(new { data = contacts }, JsonRequestBehavior.AllowGet)); } }
// POST: api/books public void Post(AuthorInfo b) { using (PracticeEntities x = new PracticeEntities()) { x.AuthorInfoes.Add(b); x.SaveChanges(); } }
public ActionResult LoadData() { try { //Creating instance of DatabaseContext class using (PracticeEntities _context = new PracticeEntities()) { var draw = Request.Form.GetValues("draw").FirstOrDefault(); var start = Request.Form.GetValues("start").FirstOrDefault(); var length = Request.Form.GetValues("length").FirstOrDefault(); var sortColumn = Request.Form.GetValues("columns[" + Request.Form.GetValues("order[0][column]").FirstOrDefault() + "][name]").FirstOrDefault(); var sortColumnDir = Request.Form.GetValues("order[0][dir]").FirstOrDefault(); var searchValue = Request.Form.GetValues("search[value]").FirstOrDefault(); //Paging Size (10,20,50,100) int pageSize = length != null?Convert.ToInt32(length) : 0; int skip = start != null?Convert.ToInt32(start) : 0; int recordsTotal = 0; // Getting all Customer data var customerData = (from tempcustomer in _context.Contacts select tempcustomer); //Sorting if (!(string.IsNullOrEmpty(sortColumn) && string.IsNullOrEmpty(sortColumnDir))) { customerData = customerData.OrderBy(sortColumn + " " + sortColumnDir); } //Search if (!string.IsNullOrEmpty(searchValue)) { customerData = customerData.Where(m => m.FirstName == searchValue || m.LastName == searchValue || m.Email == searchValue || m.City == searchValue || m.State == searchValue || m.Zip == searchValue); } //total number of rows count recordsTotal = customerData.Count(); //Paging var data = customerData.Skip(skip).Take(pageSize).ToList(); //Returning Json Data return(Json(new { draw = Convert.ToInt32(draw), recordsFiltered = recordsTotal, recordsTotal = recordsTotal, data = data })); } } catch (Exception) { throw; } }
public static bool Login(string username, string password) { using (PracticeEntities entities = new PracticeEntities()) { return (entities.Users.Any( user => user.UserName.Equals(username, StringComparison.OrdinalIgnoreCase) && user.Password == password)); } }
public ActionResult Articles() { IEnumerable <Article> articles = null; using (var context = new PracticeEntities()) { articles = context.Articles.ToList(); } return(View(articles)); }
public ActionResult Edit([Bind(Include = "Id,FirstName,LastName,Email,PhonePrimary,PhoneSecondary,Birthday,StreetAddress1,StreetAddress2,City,State,Zip")] Contact contact) { using (PracticeEntities _context = new PracticeEntities()) { if (ModelState.IsValid) { _context.Entry(contact).State = EntityState.Modified; _context.SaveChanges(); return(RedirectToAction("Index")); } return(View(contact)); } }
public void Addcustomer(int id, int age, decimal salary, string address, string name) { var dbContaxt = new PracticeEntities(); CUSTOMER cust = new CUSTOMER(); cust.ID = practice.CUSTOMERS.Max(c => c.ID) + 1; cust.ADDRESS = address; cust.SALARY = salary; cust.NAME = name; cust.AGE = age; dbContaxt.CUSTOMERS.Add(cust); dbContaxt.SaveChanges(); // return cust(); }
public HttpResponseMessage Get(int id) { using (PracticeEntities pe = new PracticeEntities()) { var entity = pe.Employees.FirstOrDefault(x => x.ID == id); if (entity != null) { return(Request.CreateResponse(HttpStatusCode.OK, entity)); } else { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, $"The Employee with ID = {id} is not found")); } } }
public JsonResult DeleteContact(int?ID) { using (PracticeEntities _context = new PracticeEntities()) { var contact = _context.Contacts.Find(ID); if (ID == null) { return(Json(data: "Not Deleted", behavior: JsonRequestBehavior.AllowGet)); } _context.Contacts.Remove(contact); _context.SaveChanges(); return(Json(data: "Deleted", behavior: JsonRequestBehavior.AllowGet)); } }
public HttpResponseMessage Get(int id) { using (PracticeEntities entities = new PracticeEntities()) { var entity = entities.Employees.FirstOrDefault(emp => emp.employee_id == id); if (entity != null) { return(Request.CreateResponse(HttpStatusCode.OK, entity)); } else { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Employee with id" + id.ToString() + " doesnot exist")); } } }
public HttpResponseMessage authrequiredbookslist(string author = "ALL") { string username = Thread.CurrentPrincipal.Identity.Name; using (PracticeEntities x = new PracticeEntities()) { if (x.BookInfoes.Where(e => e.AuthorName.ToLower() == username.ToLower()) != null) { return(Request.CreateResponse(HttpStatusCode.OK, x.BookInfoes.Where(e => e.AuthorName.ToLower() == username.ToLower()).ToList())); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } } }
public HttpResponseMessage Post([FromBody] Employee emp) { try { using (PracticeEntities entities = new PracticeEntities()) { entities.Employees.Add(emp); entities.SaveChanges(); } var message = Request.CreateResponse(HttpStatusCode.Created, emp); message.Headers.Location = new Uri(Request.RequestUri + emp.employee_id.ToString()); return(message); } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage Delete(int id) { try { using (PracticeEntities pe = new PracticeEntities()) { var entity = pe.Employees.FirstOrDefault(x => x.ID == id); if (entity == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, $"The employee with ID = {id} not found to delete")); } pe.Employees.Remove(entity); pe.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage Get(string gender = "all") { string username = Thread.CurrentPrincipal.Identity.Name; using (PracticeEntities entities = new PracticeEntities()) { switch (/*gender.ToLower()*/ username.ToLower()) { //case "all": // return Request.CreateResponse(HttpStatusCode.OK, entities.Employees.ToList()); case "male": return(Request.CreateResponse(HttpStatusCode.OK, entities.Employees.Where(emp => emp.gender == "male").ToList())); case "female": return(Request.CreateResponse(HttpStatusCode.OK, entities.Employees.Where(emp => emp.gender == "female").ToList())); default: return(Request.CreateResponse(HttpStatusCode.BadRequest, "Value for gender must be all, male or female")); } } }
public HttpResponseMessage Get(string gender = "All") { var username = Thread.CurrentPrincipal.Identity.Name; using (PracticeEntities pe = new PracticeEntities()) { switch (username.ToLower()) { case "male": return(Request.CreateResponse(HttpStatusCode.OK, pe.Employees.Where(x => x.Gender.ToLower().Equals("male")).ToList())); case "female": return(Request.CreateResponse(HttpStatusCode.OK, pe.Employees.Where(x => x.Gender.ToLower().Equals("female")).ToList())); default: return(Request.CreateResponse(HttpStatusCode.BadRequest)); } //switch (gender.ToLower()) //{ // case "all": return Request.CreateResponse(HttpStatusCode.OK, pe.Employees.ToList()); // case "male": return Request.CreateResponse(HttpStatusCode.OK, pe.Employees.Where(x => x.Gender.ToLower().Equals("male")).ToList()); // case "female": return Request.CreateResponse(HttpStatusCode.OK, pe.Employees.Where(x => x.Gender.ToLower().Equals("female")).ToList()); // default: return Request.CreateErrorResponse(HttpStatusCode.BadRequest, $"The gender values must be All, Female or Male.{gender} is not a valid value."); //} } }
// DELETE: api/books/5 public HttpResponseMessage Delete(int id) { try { using (PracticeEntities x = new PracticeEntities()) { var y = x.BookInfoes.FirstOrDefault(e => e.ID == id); if (y == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Book with Id=" + id.ToString() + " not found")); } else { x.BookInfoes.Remove(x.BookInfoes.FirstOrDefault(e => e.ID == id)); x.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, y)); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage Put(int id, [FromBody] Employee employee) { try { using (PracticeEntities pe = new PracticeEntities()) { var entity = pe.Employees.FirstOrDefault(x => x.ID == id); if (entity == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, $"The employee with ID = {id} could not be found to update!")); } entity.FirstName = employee.FirstName; entity.LastName = employee.LastName; entity.Gender = employee.Gender; entity.Salary = employee.Salary; pe.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public BaseRepository(PracticeEntities Context) { this.Context = Context; this.DbSet = Context.Set <TEntity>(); }