public static void SubmitOrder(Order order)
 {
     using (var db = new WorkersBenefitsDB2())
     {
         db.orders.Add(order.ToDB());
     }
 }
Beispiel #2
0
 public static bool IsWorkerPreRegistered(string idNumber)
 {
     using (var db = new WorkersBenefitsDB2())
     {
         return(db.workers.Any(item => item.id_number == idNumber));
     }
 }
 /// <summary>
 /// Returns the most featured product in the system.
 /// </summary>
 /// <returns></returns>
 public static List <Product> GetFeaturedProduct()
 {
     using (var db = new WorkersBenefitsDB2())
     {
         return(db.products.Select(ServiceObjectsExtensions.ToSvc).ToList());
     }
 }
Beispiel #4
0
 public static void SaveWorker(Worker worker)
 {
     using (var db = new WorkersBenefitsDB2())
     {
         db.Entry(worker).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
Beispiel #5
0
 //Company Point-Of-View :::
 /// <summary>
 /// Returns all workers of the given company.
 /// </summary>
 /// <param name="companyId"></param>
 /// <returns></returns>
 public static List <Worker> GetAllWorkers(int companyId)
 {
     using (var db = new WorkersBenefitsDB2())
     {
         return(db.workers.Where(worker => worker.company_id == companyId).AsEnumerable()
                .Select(ServiceObjectsExtensions.ToSvc)
                .ToList());
     }
 }
Beispiel #6
0
 public static void SetWorkerRegistered(string idNumber)
 {
     using (var db = new WorkersBenefitsDB2())
     {
         var workerToUpdate = db.workers.Single(item => item.id_number == idNumber);
         db.Entry(workerToUpdate).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
Beispiel #7
0
        //public static void SaveWorker(Worker worker)
        //{
        //    try
        //    {
        //        using (var db = new WorkersBenefitsDB2())
        //        {
        //            db.Entry(worker).State = EntityState.Modified;
        //            db.SaveChanges();
        //        }

        //    }
        //    catch (Exception ex)
        //    {
        //        m_logger.Error(ex);
        //        throw;
        //    }
        //}

        public static void DeleteWorker(int workerId)
        {
            using (var db = new WorkersBenefitsDB2())
            {
                var workerToDelete = db.workers.Find(workerId);
                db.workers.Remove(workerToDelete);
                db.SaveChanges();
            }
        }
 /// <summary>
 /// Returns the most featured product in the given category.
 /// </summary>
 /// <returns></returns>
 public static List <Product> GetFeaturedProduct(int categoryId)
 {
     using (var db = new WorkersBenefitsDB2())
     {
         return(db.products
                .Where(item => item.category_id == categoryId).AsEnumerable()
                .Select(ServiceObjectsExtensions.ToSvc).ToList());
     }
 }
Beispiel #9
0
        public static Company GetCompany(int company_id)
        {
            using (var db = new WorkersBenefitsDB2())
            {
                var dbObj = db.companies
                            .SingleOrDefault(item => item.company_id == company_id);

                return(dbObj?.ToSvc());
            }
        }
Beispiel #10
0
        public static Voucher GetVoucher(int voucherId)
        {
            using (var db = new WorkersBenefitsDB2())
            {
                var dbObj = db.vouchers
                            .SingleOrDefault(item => item.voucher_id == voucherId);

                return(dbObj?.ToSvc());
            }
        }
        //CategoryPage:

        public static Category GetCategory(int categoryId)
        {
            using (var db = new WorkersBenefitsDB2())
            {
                var dbObj = db.categories
                            .SingleOrDefault(item => item.category_id == categoryId);

                return(dbObj?.ToSvc());
            }
        }
 /// <summary>
 /// Returns all categories in the systems.
 /// sequence is returned in the order of precedence.
 /// </summary>
 /// <returns></returns>
 public static List <Category> GetAllCategories()
 {
     using (var db = new WorkersBenefitsDB2())
     {
         return(db.categories
                .Select(ServiceObjectsExtensions.ToSvc)
                .OrderBy(item => item.Precedence)
                .ToList());
     }
 }
        public static Product GetProduct(int productId)
        {
            using (var db = new WorkersBenefitsDB2())
            {
                var dbObj = db.products
                            .SingleOrDefault(item => item.product_id == productId);

                return(dbObj?.ToSvc());
            }
        }
        public static Order GetOrder(int orderId)
        {
            using (var db = new WorkersBenefitsDB2())
            {
                var dbObj = db.orders
                            .SingleOrDefault(item => item.order_id == orderId);

                return(dbObj?.ToSvc());
            }
        }
 //Orders Page:
 /// <summary>
 /// Returns all orders associated with the given workerId.
 /// </summary>
 /// <param name="workerId"></param>
 /// <returns></returns>
 public static List <Order> GetOrders(int workerId)
 {
     using (var db = new WorkersBenefitsDB2())
     {
         return(db.orders.Where(item => item.worker_id == workerId)
                .AsEnumerable()
                .Select(ServiceObjectsExtensions.ToSvc)
                .ToList());
     }
 }
 //MainPage:
 public static FeaturedProductsList GetFeaturedProducts()
 {
     using (var db = new WorkersBenefitsDB2())
     {
         var items = db.products.Take(10).AsEnumerable()
                     .Select(ServiceObjectsExtensions.ToSvc)
                     .OrderBy(item => item.Precedence).ToList();
         return(new FeaturedProductsList(items));    //todo. add random
     }
 }
Beispiel #17
0
 /// <summary>
 /// Returns all vouchers of the given worker.
 /// </summary>
 public static List <Voucher> GetAll(int workerId)
 {
     using (var db = new WorkersBenefitsDB2())
     {
         return(db.voucher_grants.Where(item => item.worker_id == workerId)
                .Select(voucherGrant => voucherGrant.voucher)
                .AsEnumerable()
                .Select(ServiceObjectsExtensions.ToSvc)
                .ToList());
     }
 }
 /// <summary>
 /// Applies a search and returns the search results.
 /// </summary>
 /// <param name="search"></param>
 /// <returns></returns>
 public static ProductsSearchResults Search(string criteria)
 {
     using (var db = new WorkersBenefitsDB2())
     {
         var items = db.products.Take(10).AsEnumerable()
                     .Where(item => item.title.Contains(criteria)).AsEnumerable()
                     .Select(ServiceObjectsExtensions.ToSvc)
                     .OrderBy(item => item.Precedence).ToList();
         return(new ProductsSearchResults(items));    //todo. add random
     }
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="full">if fill with their corresponding featured products</param>
 /// <returns></returns>
 public static FeaturedCategoriesList GetFeaturedCategories(bool full)
 {
     using (var db = new WorkersBenefitsDB2())
     {
         var items = db.categories.Take(5).AsEnumerable()
                     .Select(ServiceObjectsExtensions.ToSvc)
                     .OrderBy(item => item.Precedence).ToList();
         for (int i = 0; i < items.Count; i++)   //Todo. nativize.
         {
             items[i].Products = GetFeaturedProducts(items[i].CategoryId).Values.ToList();
         }
         return(new FeaturedCategoriesList(items));    //todo. add random
     }
 }
Beispiel #20
0
 /// <summary>
 /// Preliminarily creates the worker (by company side)
 /// </summary>
 /// <param name="worker"></param>
 public static void CreateWorker(Worker worker)
 {
     try
     {
         using (var db = new WorkersBenefitsDB2())
         {
             db.workers.Add(worker.ToDB());
             db.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         m_logger.Error(ex);
         throw;
     }
 }