Ejemplo n.º 1
0
        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));
            }
        }
Ejemplo n.º 2
0
        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));
            }
        }
Ejemplo n.º 3
0
        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));
            }
        }
Ejemplo n.º 4
0
        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));
            }
        }
Ejemplo n.º 5
0
 /// <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();
         }
     }
 }
Ejemplo n.º 6
0
        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));
            }
        }
Ejemplo n.º 7
0
        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));
            }
        }
Ejemplo n.º 8
0
 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));
         }
     }
 }
Ejemplo n.º 9
0
 /// <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);
     }
 }
Ejemplo n.º 10
0
 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));
         }
     }
 }
Ejemplo n.º 11
0
 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;
         }
     }
 }
Ejemplo n.º 12
0
 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"));
         }
     }
 }
Ejemplo n.º 13
0
 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"));
         }
     }
 }
Ejemplo n.º 14
0
        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"));
                }
            }
        }
Ejemplo n.º 15
0
 public StoresController()
 {
     _context = new OnboardingContext();
 }
Ejemplo n.º 16
0
 public OnboardService(OnboardingContext context)
 {
     _context = context;
 }
 public ProductsController()
 {
     _context = new OnboardingContext();
 }
Ejemplo n.º 18
0
 public ProductsController(OnboardingContext context)
 {
     _context = context;
 }
 public HomeController(ILogger <HomeController> logger)
 {
     _db     = new OnboardingContext();
     _logger = logger;
 }
Ejemplo n.º 20
0
 public CustomersController()
 {
     _context = new OnboardingContext();
 }
Ejemplo n.º 21
0
 public CustomersController(OnboardingContext context)
 {
     _context = context;
 }
Ejemplo n.º 22
0
 public StoresController(OnboardingContext context)
 {
     _context = context;
 }
Ejemplo n.º 23
0
 /// <summary>
 /// Constructor
 /// </summary>
 public EmployeeRepository()
 {
     ctx = new OnboardingContext();
 }