public JsonResult StoreList(string sortColumnName, string sortOrder, int pageSize, int currentPage) { List <Store> list = new List <Store>(); int totalPage = 0; int totalRecord = 0; using (var db = new OnboardingContext()) { var stores = db.Stores; totalRecord = stores.Count(); if (pageSize > 0) { totalPage = totalRecord / pageSize + ((totalRecord % pageSize) > 0 ? 1 : 0); list = stores.Select(x => new Store() { Id = x.Id, Name = x.Name, Address = x.Address }).OrderBy(sortColumnName + " " + sortOrder).Skip(pageSize * (currentPage - 1)).Take(pageSize).ToList(); } else { list = stores.ToList(); } var result = new { list = list, totalRecord = totalRecord, totalPage = totalPage }; return(Json(result)); } }
public JsonResult SalesList(string sortColumnName, string sortOrder, int pageSize, int currentPage) { List <Sales> list = new List <Sales>(); int totalPage = 0; int totalRecord = 0; using (var db = new OnboardingContext()) { var sales = db.Sales; totalRecord = sales.Count(); if (pageSize > 0) { totalPage = totalRecord / pageSize + ((totalRecord % pageSize) > 0 ? 1 : 0); list = sales.Select(x => new Sales() { Id = x.Id, Customer = x.Customer, Product = x.Product, Store = x.Store, DateSold = x.DateSold }).OrderBy(sortColumnName + " " + sortOrder).Skip(pageSize * (currentPage - 1)).Take(pageSize).ToList(); } else { list = sales.ToList(); } var result = new { list = list, totalRecord = totalRecord, totalPage = totalPage }; return(Json(result)); } }
public JsonResult ProductList(string sortColumnName, string sortOrder, int pageSize, int currentPage) { List <Product> list = new List <Product>(); int totalPage = 0; int totalRecord = 0; using (var db = new OnboardingContext()) { var products = db.Products; totalRecord = products.Count(); if (pageSize > 0) { totalPage = totalRecord / pageSize + ((totalRecord % pageSize) > 0 ? 1 : 0); list = products.Select(x => new Product() { Id = x.Id, Name = x.Name, Price = x.Price }).OrderBy(sortColumnName + " " + sortOrder).Skip(pageSize * (currentPage - 1)).Take(pageSize).ToList(); } else { list = products.ToList(); } var result = new { list = list, totalRecord = totalRecord, totalPage = totalPage }; return(Json(result)); } }
public JsonResult Get() { using (var db = new OnboardingContext()) { var customers = db.Customers.Select(x => new Customer() { Id = x.Id, Name = x.Name, Address = x.Address }).ToList(); return(Json(customers)); } }
/// <summary> /// Deletes Employee record /// </summary> /// <param name="empId"></param> public void Delete(int empId) { using (OnboardingContext ctx = new OnboardingContext()) { var employeeToDelete = ctx.Employees.Find(empId); if (employeeToDelete != null) { //entity is already in the context var attachedEntry = ctx.Entry(employeeToDelete).Entity; ctx.Employees.Remove(attachedEntry); ctx.SaveChanges(); } } }
public JsonResult ProductsList() { using (var db = new OnboardingContext()) { var products = db.Products.Select(x => new Product() { Id = x.Id, Name = x.Name, Price = x.Price }).ToList(); return(Json(products)); } }
public JsonResult StoreListSales() { using (var db = new OnboardingContext()) { var stores = db.Stores.Select(x => new Store() { Id = x.Id, Name = x.Name, Address = x.Address }).ToList(); return(Json(stores)); } }
public ActionResult CreateProduct([FromBody] Product product) { using (var db = new OnboardingContext()) { if (ModelState.IsValid) { db.Products.Add(product); db.SaveChanges(); return(StatusCode(StatusCodes.Status201Created)); } else { return(StatusCode(StatusCodes.Status400BadRequest)); } } }
/// <summary> /// Updates existing employee record /// </summary> /// <param name="employee"></param> public bool Update(Employee employee) { using (OnboardingContext ctx = new OnboardingContext()) { var updatedEmployee = ctx.Employees.Find(employee.Id); if (updatedEmployee != null) { //entity is already in the context var attachedEntry = ctx.Entry(updatedEmployee); attachedEntry.CurrentValues.SetValues(employee); ctx.SaveChanges(); return(true); } return(false); } }
public ActionResult Create([FromBody] Customer customer) { //Does not implement catching exception using (var db = new OnboardingContext()) { if (ModelState.IsValid) { db.Customers.Add(customer); db.SaveChanges(); return(StatusCode(StatusCodes.Status201Created)); } else { return(StatusCode(StatusCodes.Status400BadRequest)); } } }
public ActionResult DeleteSales(int id) { using (var db = new OnboardingContext()) { try { var entity = db.Sales.Find(id); db.Sales.Remove(entity); db.SaveChanges(); return(Ok("Sales deleted")); } catch { throw; } } }
public ActionResult EditProduct(int id, [FromBody] Product product) { using (var db = new OnboardingContext()) { if (ModelState.IsValid) { var entity = db.Products.Find(id); entity.Name = product.Name; entity.Price = product.Price; db.SaveChanges(); return(Ok("Record Updated Succesfully...")); } else { return(NotFound("No record has been found against this id")); } } }
public ActionResult Edit(int id, [FromBody] Customer customer) { using (var db = new OnboardingContext()) { if (ModelState.IsValid) { var entity = db.Customers.Find(id); entity.Name = customer.Name; entity.Address = customer.Address; db.SaveChanges(); return(Ok("Record Updated Succesfully...")); } else { return(NotFound("No record has been found against this id")); } } }
public ActionResult EditSales(int id, [FromBody] Sales sales) { using (var db = new OnboardingContext()) { if (ModelState.IsValid) { var entity = db.Sales.Find(id); entity.CustomerId = sales.CustomerId; entity.ProductId = sales.ProductId; entity.StoreId = sales.StoreId; entity.DateSold = sales.DateSold; db.SaveChanges(); return(Ok("Record Updated Succesfully...")); } else { return(NotFound("No record has been found against this id")); } } }
public StoresController() { _context = new OnboardingContext(); }
public OnboardService(OnboardingContext context) { _context = context; }
public ProductsController() { _context = new OnboardingContext(); }
public ProductsController(OnboardingContext context) { _context = context; }
public HomeController(ILogger <HomeController> logger) { _db = new OnboardingContext(); _logger = logger; }
public CustomersController() { _context = new OnboardingContext(); }
public CustomersController(OnboardingContext context) { _context = context; }
public StoresController(OnboardingContext context) { _context = context; }
/// <summary> /// Constructor /// </summary> public EmployeeRepository() { ctx = new OnboardingContext(); }