public List <PurchasingVendor> ListVendors()
        {
            // Access the database
            using (var context = new ToolsContext())
            {
                var purchaseOrders = from po in context.PurchaseOrders
                                     where po.OrderDate == null
                                     select po;


                var results = from vendor in context.Vendors
                              orderby vendor.VendorID
                              select new
                {
                    VendorID        = vendor.VendorID,
                    VendorName      = vendor.VendorName,
                    PurchaseOrderID = from vendorpo in purchaseOrders
                                      where vendorpo.VendorID == vendor.VendorID
                                      select vendorpo.PurchaseOrderID
                };
                var finalResults = from po in results
                                   select new PurchasingVendor()
                {
                    VendorID           = po.VendorID,
                    VendorNameAndOrder = po.PurchaseOrderID.FirstOrDefault() != 0 ? po.VendorName + " - " + po.PurchaseOrderID.FirstOrDefault().ToString() : po.VendorName + " - none"
                };

                return(finalResults.ToList());
            }
        }
Esempio n. 2
0
 public LineBotApp(LineMessagingClient lineMessagingClient, jafleetContext context, ToolsContext toolsContext, IServiceScopeFactory serviceScopeFactory)
 {
     this.messagingClient = lineMessagingClient;
     _context             = context;
     _tContext            = toolsContext;
     _services            = serviceScopeFactory;
 }
Esempio n. 3
0
        public async Task RunAsync(ToolsContext context)
        {
            if (context.LatestVersion == null)
            {
                var matchingVersions = context.Versions.OrderBy(a => a.GetNumber());
                if (string.IsNullOrEmpty(context.VersionNumber))
                {
                    Console.WriteLine("-----------------------INSTALL PROGRESS-------------------------");
                    Console.WriteLine("INSTALLING VERSION: " + matchingVersions.Last().VersionNumber);
                    Console.WriteLine("-----------------------++++++++++++++++-------------------------");
                    var portalVersions = await InstallingVersion(matchingVersions, context);

                    foreach (var portalVersion in portalVersions)
                    {
                        await context.VersionRepository.AddAsync(portalVersion);
                    }
                }
                else
                {
                    var requestVersionNumber = context.VersionNumber.ToVersionNumber();
                    matchingVersions = matchingVersions.Where(a => a.VersionNumber.ToVersionNumber() <= requestVersionNumber).OrderBy(b => b.GetNumber());
                    var portalVersions = await InstallingVersion(matchingVersions, context);

                    foreach (var portalVersion in portalVersions)
                    {
                        await context.VersionRepository.AddAsync(portalVersion);
                    }
                }
            }
            else
            {
                Console.WriteLine("Sorry we can't install any version because it is already exist.");
            }
        }
Esempio n. 4
0
        public async Task RunAsync(ToolsContext context)
        {
            if (context.LatestVersion != null)
            {
                var requestingVersionNumber = context.VersionNumber.ToVersionNumber();
                if (context.LatestVersion.GetNumber() < requestingVersionNumber)
                {
                    var matchingVersions = context.Versions.Where(
                        a => a.GetNumber() > context.LatestVersion.GetNumber() &&
                        a.GetNumber() <= requestingVersionNumber);
                    Console.WriteLine("---------------------UPGRADE PROGRESS-----------------------");
                    Console.WriteLine("UPGRADE VERSION: " + matchingVersions.Last().VersionNumber);
                    Console.WriteLine("-----------------------++++++++++++++++-------------------------");

                    var portalVersions = await UpgradingVersion(matchingVersions, context);

                    foreach (var portalVersion in portalVersions)
                    {
                        await context.VersionRepository.AddAsync(portalVersion);
                    }
                }
                else
                {
                    Console.WriteLine(string.Format("Oops we can't upgrade version because your request is {0} but the current is {1}", context.VersionNumber, context.LatestVersion.VersionNumber));
                }
            }
            else
            {
                Console.WriteLine("Oops we can't find any installation in the database, please use 'install' command before upgrading.");
            }
        }
        private void OverwriteBccSourceFeedData(string sourceFeedLocation)
        {
            // delete all records
            using (var db = new ToolsContext())
            {
                db.Database.ExecuteSqlCommand("DELETE FROM [BccSourceFeedItem]");


                //db.Configuration.AutoDetectChangesEnabled = false;
                //var feedItems = db.BccSourceFeedItems;
                //db.BccSourceFeedItems.RemoveRange(feedItems);
                //db.SaveChanges();
            }
            // read the source file and add each record to the DB
            using (var sr = new StreamReader(sourceFeedLocation))
            {
                var reader = new CsvReader(sr);

                reader.Configuration.RegisterClassMap <BccSourceFeedItemCsvMap>();

                var records = reader.GetRecords <BccSourceFeedItem>().ToList();

                foreach (IEnumerable <BccSourceFeedItem> batch in Partition(records, 1000))
                {
                    InsertBccSourceFeedItems(batch.ToList());
                }
            }
        }
Esempio n. 6
0
        public async Task ExecuteAsync()
        {
            using (var context = new ToolsContext(AppConfig.ToolsOption.Options))
            {
                //実行中に更新
                var task = context.NotificationTasks.Where(t => t.TaskId == this.TaskId).SingleOrDefault();
                task.Status = Noobow.Commons.Constants.NotificationTaskStatusEnum.EXECUTING;
                context.SaveChanges();
                //待ち時間を計算
                int waitTime = Convert.ToInt32((task.NotificationTime - DateTime.Now).Value.TotalMilliseconds);
                //待つ
                Thread.Sleep(waitTime);
                //通知
                var quickReply = new QuickReply();
                quickReply.Items.Add(new QuickReplyButtonObject(new MessageTemplateAction("5分後", $"{CommandEum.PlanNotice.GetStringValue()} a5 {task.NotificationDetail}")));
                quickReply.Items.Add(new QuickReplyButtonObject(new MessageTemplateAction("10分後", $"{CommandEum.PlanNotice.GetStringValue()} a10 {task.NotificationDetail}")));
                quickReply.Items.Add(new QuickReplyButtonObject(new MessageTemplateAction("30分後", $"{CommandEum.PlanNotice.GetStringValue()} a30 {task.NotificationDetail}")));
                quickReply.Items.Add(new QuickReplyButtonObject(new MessageTemplateAction("1時間後", $"{CommandEum.PlanNotice.GetStringValue()} a60 {task.NotificationDetail}")));
                await LineMessagingClientManager.GetInstance().PushMessageAsync(task.NotificationTo, new List <ISendMessage> {
                    new TextMessage(task.NotificationDetail, quickReply)
                });

                //実行済みに更新
                task.Status = NotificationTaskStatusEnum.EXECUTED;
                context.SaveChanges();
            }
        }
Esempio n. 7
0
 public List <Category> Categories_List()
 {
     using (ToolsContext context = new ToolsContext())
     {
         return(context.Categories.ToList());
     }
 }
        public void StartPurchaseOrder(List <SuggestedOrderItems> podetails, int employeeid, int vendorid, decimal tax, decimal sub)
        {
            using (ToolsContext context = new ToolsContext())
            {
                PurchaseOrder newOrder = new PurchaseOrder()
                {
                    EmployeeID = employeeid,
                    VendorID   = vendorid,
                    OrderDate  = null,
                    TaxAmount  = tax,
                    SubTotal   = sub
                };

                context.PurchaseOrders.Add(newOrder);

                foreach (var po in podetails)
                {
                    newOrder.PurchaseOrderDetails.Add(new PurchaseOrderDetail()
                    {
                        StockItemID = po.ID, Quantity = po.PurchaseOrderQuantity
                    });
                }

                context.PurchaseOrders.Add(newOrder);

                context.SaveChanges();
            }
        }
Esempio n. 9
0
        public List <UserProfile> ListAllUsers()
        {
            var rm     = new RoleManager();
            var result = from person in Users.ToList()
                         select new UserProfile()
            {
                UserId          = person.Id,
                UserName        = person.UserName,
                Email           = person.Email,
                EmailConfirmed  = person.EmailConfirmed,
                CustomerId      = person.CustomerId,
                EmployeeId      = person.EmployeeId,
                RoleMemberships = person.Roles.Select(r => rm.FindById(r.RoleId).Name)
            };

            // Get any first/last names of users
            using (var context = new ToolsContext())
            {
                foreach (var person in result)
                {
                    if (person.EmployeeId.HasValue)
                    {
                        person.FirstName = context.Employees.Find(person.EmployeeId).FirstName;
                        person.LastName  = context.Employees.Find(person.EmployeeId).LastName;
                    }
                }
            }

            return(result.ToList());
        }
        public void DeleteOrder(int purchaseorderid, List <SuggestedOrderItems> stockitemids)
        {
            using (var context = new ToolsContext())
            {
                var purchaseorder = context.PurchaseOrders.Find(purchaseorderid);
                if (purchaseorder == null)
                {
                    throw new ArgumentException("Invalid PO ID - Does not exist");
                }
                List <PurchaseOrderDetail> toRemove = new List <PurchaseOrderDetail>();

                foreach (var item in purchaseorder.PurchaseOrderDetails)
                {
                    bool stockitemidmatch = stockitemids.Any(x => x.ID == item.StockItemID);
                    if (stockitemidmatch)
                    {
                        toRemove.Add(item);
                    }
                }
                foreach (var item in toRemove)
                {
                    context.PurchaseOrderDetails.Remove(item);
                }

                context.PurchaseOrders.Remove(purchaseorder);

                context.SaveChanges();
            }
        }
Esempio n. 11
0
        public List <CategoryDTO> CategoryStockList()
        {
            using (ToolsContext context = new ToolsContext())
            {
                #region Student Code here
                //insert query code


                var data = from cat in context.Categories
                           orderby cat.CategoryID
                           select new CategoryDTO()
                {
                    CategoryDescription = cat.Description,
                    Stocks = from item in cat.StockItems
                             select new CategoryStockItem()
                    {
                        Name   = item.Description,
                        OnHand = item.QuantityOnHand,
                        Markup = item.SellingPrice - item.PurchasePrice
                    }
                };


                //replace the following line of code to return your results
                return(data.ToList());

                #endregion
            }
        }
        public void RemoveFromOrder(int purchaseorderid, int stockitemid)
        {
            using (ToolsContext context = new ToolsContext())
            {
                List <string> errors = new List <string>();

                if (errors.Count > 0)
                {
                    throw new BusinessRuleException("Unable to add to Purchase Order", errors);
                }

                var purchaseorder = context.PurchaseOrders.Find(purchaseorderid);
                if (purchaseorder == null)
                {
                    throw new ArgumentException("Invalid Purchase Order ID - does not exist");
                }

                List <PurchaseOrderDetail> toRemove = new List <PurchaseOrderDetail>();
                foreach (var item in purchaseorder.PurchaseOrderDetails)
                {
                    if (item.StockItemID == stockitemid && item.PurchaseOrderID == purchaseorderid)
                    {
                        toRemove.Add(item);
                    }
                }

                foreach (var item in toRemove)
                {
                    context.PurchaseOrderDetails.Remove(item);
                }
                context.SaveChanges();
            }
        }
        public void UpdatePurchaseOrder(List <SuggestedOrderItems> podetails, PurchaseOrder po)
        {
            using (var context = new ToolsContext())
            {
                var purchaseorder = context.PurchaseOrders.Find(po.PurchaseOrderID);

                if (purchaseorder == null)
                {
                    throw new ArgumentException("Invalid PO ID - Does not exist");
                }

                foreach (var item in podetails)
                {
                    var purchaseorderdetail = purchaseorder.PurchaseOrderDetails.Single(x => x.StockItemID == item.ID);
                    purchaseorderdetail.Quantity      = item.PurchaseOrderQuantity;
                    purchaseorderdetail.PurchasePrice = item.UnitPrice;
                    context.Entry <PurchaseOrderDetail>(context.PurchaseOrderDetails.Attach(purchaseorderdetail)).State = System.Data.Entity.EntityState.Modified;
                }


                purchaseorder.SubTotal  = po.SubTotal;
                purchaseorder.TaxAmount = po.TaxAmount;

                context.Entry <PurchaseOrder>(context.PurchaseOrders.Attach(purchaseorder)).State = System.Data.Entity.EntityState.Modified;

                context.SaveChanges();
            }
        }
Esempio n. 14
0
            private void GenerateAdCustomizerFeed(int projectId, string localFilePath)
            {
                var items     = new List <List <string> >();
                var header    = new List <string>();
                var hashtable = new HashSet <string>();

                // create the join
                using (var db = new ToolsContext())
                {
                    db.Configuration.AutoDetectChangesEnabled = false;
                    db.Configuration.ValidateOnSaveEnabled    = false;
                    db.Database.CommandTimeout = 180;

                    //var input = (from i in db.PointOfInterestAdWordsLocations
                    //             join l in db.AdWordsLocations on i.AdWordsLocationId equals l.Id
                    //             join s in db.StoreDatas on i.PoiId equals s.GmbStoreId
                    //             where i.AdWordsLocationProjectId == projectId
                    //             select new
                    //             {
                    //                 i.AdWordsLocationId,
                    //                 l.CanonicalName,
                    //                 s.LocationName,
                    //                 s.StoreName20,
                    //                 s.StoreName25,
                    //                 s.StoreName30
                    //             });

                    var input = db.Database.SqlQuery <GenericLocation>(@"select a.CanonicalName as 'TargetLocation', s.LocationName, s.StoreName20, s.StoreName25, s.StoreName30
from PointOfInterestAdWordsLocation p join AdWordsLocation a on p.AdWordsLocationId = a.Id
join StoreData s on p.PoiId = s.GmbStoreId
where p.AdWordsLocationProjectId = " + projectId);


                    foreach (var r in input)
                    {
                        var lac = new GenericLocationBusinessDataItem();
                        // set header once
                        if (header.Count == 0)
                        {
                            header = lac.Header;
                        }
                        // construct targetLocation
                        lac.TargetLocation            = r.TargetLocation.Trim();
                        lac.TargetLocationRestriction = "";
                        lac.LocationName = r.LocationName;
                        lac.StoreName20  = r.StoreName20;
                        lac.StoreName25  = r.StoreName25;
                        lac.StoreName30  = r.StoreName30;

                        // avoid duplicate entries
                        if (!hashtable.Contains(lac.CustomId))
                        {
                            hashtable.Add(lac.CustomId);
                            items.Add(lac.Row);
                        }
                    }
                }
                // store feed
                AddToFile(items, localFilePath, header, false);
            }
Esempio n. 15
0
 public Category Categories_FindbyID(int categoryid)
 {
     using (ToolsContext context = new ToolsContext())
     {
         return(context.Categories.Find(categoryid));
     }
 }
        private void OverwriteStoreData(string sourceFileLocation, string clientName)
        {
            // delete all records for this ClientName from DB
            using (var db = new ToolsContext())
            {
                db.Configuration.AutoDetectChangesEnabled = false;
                var stores = db.StoreDatas.Where(x => x.ClientName == clientName);
                db.StoreDatas.RemoveRange(stores);
                db.SaveChanges();
            }
            // read the source file and add each record to the DB
            using (var sr = new StreamReader(sourceFileLocation))
            {
                var reader = new CsvReader(sr);

                reader.Configuration.RegisterClassMap <StoreDataCsvMap>();
                reader.Configuration.Delimiter = ";";

                List <StoreData> records = reader.GetRecords <StoreData>().ToList();

                foreach (IEnumerable <StoreData> batch in Partition(records, 1000))
                {
                    InsertStoreData(batch.ToList());
                }
            }
        }
Esempio n. 17
0
 private ApiDatatable GetDatatable(int id)
 {
     using (var db = new ToolsContext())
     {
         var dt = db.ApiDatatables.Include("ServiceAccount").SingleOrDefault(x => x.Id.Equals(id));
         return(dt);
     }
 }
Esempio n. 18
0
            public async Task <Model> Handle(Query message)
            {
                var rtn = await _db.PriceExtensionProjects.Where(c => c.Id == message.Id).ProjectToSingleOrDefaultAsync <Model>();

                // delete all data from priceextensionproductfeeds for this project
                using (var db = new ToolsContext())
                {
                    db.Database.ExecuteSqlCommand("DELETE FROM [PriceExtensionProductFeed] WHERE PriceExtensionProjectId = " + message.Id);
                }
                // import product feed into priceextensionproductfeeds
                // read the source file and add each record to the DB
                using (var sr = new StreamReader(rtn.ProductFeedLocation))
                {
                    var reader = new CsvReader(sr);

                    reader.Configuration.RegisterClassMap <PriceExtensionProductFeedCsvMap>();

                    var records = reader.GetRecords <PriceExtensionProductFeed>().ToList();

                    records.ForEach(x => x.PriceExtensionProjectId = (int)message.Id);
                    records.ForEach(x => x.LinkLevel2 = GetBccLink(x.Link, x.Brand, 2));
                    records.ForEach(x => x.LinkLevel3 = GetBccLink(x.Link, x.Brand, 3));

                    foreach (IEnumerable <PriceExtensionProductFeed> batch in Partition(records, 1000))
                    {
                        InsertPriceExtensionProductFeedItems(batch.ToList());
                    }
                }

                // delete all data from priceextensionproductperformance for this project
                using (var db = new ToolsContext(connString))
                {
                    db.Database.ExecuteSqlCommand("DELETE FROM [PriceExtensionProductPerformance] WHERE PriceExtensionProjectId = " + message.Id);
                }

                // import product feed into priceextensionproductperformances
                // read the source file and add each record to the DB
                using (var sr = new StreamReader(rtn.ProductPerformanceFeedLocation))
                {
                    var reader = new CsvReader(sr);
                    reader.Configuration.CultureInfo = CultureInfo.CreateSpecificCulture("en-US");

                    reader.Configuration.RegisterClassMap <PriceExtensionProductPerformanceCsvMap>();

                    var records = reader.GetRecords <PriceExtensionProductPerformance>().ToList();

                    records.ForEach(x => x.PriceExtensionProjectId = (int)message.Id);

                    foreach (IEnumerable <PriceExtensionProductPerformance> batch in Partition(records, 1000))
                    {
                        InsertPriceExtensionProductPerformanceItems(batch.ToList());
                    }
                }



                return(rtn);
            }
Esempio n. 19
0
        public async Task RunAsync(ToolsContext context)
        {
            Console.WriteLine("---------------------PACKAGE APP PROGRESS-----------------------");
            Console.WriteLine($"App Name: {context.Arguments.Name}, Ouput: {context.Arguments.Output}");
            var appService = context.Services.GetService <IAppService>();
            var savePath   = await appService.Package(context.Arguments.Name, context.Arguments.Output);

            Console.WriteLine($"Package successfully: {savePath}");
            Console.WriteLine("-----------------------++++++++++++++++-------------------------");
        }
Esempio n. 20
0
        public async Task RunAsync(ToolsContext context)
        {
            Console.WriteLine("---------------------UNPACKAGE APP PROGRESS-----------------------");
            Console.WriteLine($"Package file: {context.Arguments.FilePath}, Install mode: {context.Arguments.UnpackMode}");
            var appService = context.Services.GetService <IAppService>();
            await appService.Unpack(context.Arguments.FilePath, context.Arguments.UnpackMode.ToLower() == "wipe"?InstallWay.Wipe : InstallWay.Merge);

            Console.WriteLine($"Unpack successfully!!!");
            Console.WriteLine("-----------------------++++++++++++++++-------------------------");
        }
        private void InsertBccSourceFeedItems(List <BccSourceFeedItem> records)
        {
            using (var db = new ToolsContext())
            {
                db.Configuration.AutoDetectChangesEnabled = false;
                db.Configuration.ValidateOnSaveEnabled    = false;

                db.BccSourceFeedItems.AddRange(records);
                db.SaveChanges();
            }
        }
Esempio n. 22
0
        private void UpdateDatatable(int id, DateTime lastDateDownloaded)
        {
            using (var db = new ToolsContext())
            {
                var dt = db.ApiDatatables.Include("ServiceAccount").SingleOrDefault(x => x.Id.Equals(id));

                dt.LastDateDownloaded = lastDateDownloaded;

                db.SaveChanges();
            }
        }
Esempio n. 23
0
            private void InsertPriceExtensionProductPerformanceItems(List <PriceExtensionProductPerformance> records)
            {
                using (var db = new ToolsContext(connString))
                {
                    db.Configuration.AutoDetectChangesEnabled = false;
                    db.Configuration.ValidateOnSaveEnabled    = false;

                    db.PriceExtensionProductPerformances.AddRange(records);
                    db.SaveChanges();
                }
            }
        private void InsertStoreData(List <StoreData> records)
        {
            using (var db = new ToolsContext())
            {
                db.Configuration.AutoDetectChangesEnabled = false;
                db.Configuration.ValidateOnSaveEnabled    = false;

                db.StoreDatas.AddRange(records);
                db.SaveChanges();
            }
        }
Esempio n. 25
0
 public void Categories_Delete(Category removeItem)
 {
     using (ToolsContext context = new ToolsContext())
     {
         #region Student Code here
         //insert Delete code
         var existingvalue = context.Categories.Find(removeItem.CategoryID);
         context.Categories.Remove(existingvalue);
         context.SaveChanges();
         #endregion
     }
 }
Esempio n. 26
0
 public void Categories_Add(Category item)
 {
     using (ToolsContext context = new ToolsContext())
     {
         #region Student Code here
         //insert add code
         var adding = context.Categories.Add(item); context.SaveChanges();
         //replace the following line of code to return your results
         // return 0;
         #endregion
     }
 }
Esempio n. 27
0
 public void Categories_Update(Category item)
 {
     using (ToolsContext context = new ToolsContext())
     {
         #region Student Code here
         //insert udpate code
         var updating = context.Categories.Attach(item);
         var matchingWithExistingValues = context.Entry <Category>(updating);
         matchingWithExistingValues.State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
         #endregion
     }
 }
Esempio n. 28
0
        public Task RunAsync(ToolsContext context)
        {
            if (context.LatestVersion != null)
            {
                Console.WriteLine($"Current Version: {context.LatestVersion.VersionNumber}");
                Console.WriteLine($"Last Modified Date: {context.LatestVersion.CreatedDate}");
            }
            else
            {
                Console.WriteLine("Oops we don't find any installation in the database.");
            }

            return(Task.CompletedTask);
        }
Esempio n. 29
0
        private void ThisAddIn_Startup(object sender, EventArgs e)
        {
            var rootDirectory    = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            var workingDirectory = Path.Combine(rootDirectory, "enovating", "patent-office-tools");

            try
            {
                ToolsContext.Initialize(workingDirectory);
            }
            catch (Exception exception)
            {
                MessageBox.Show("Fatal error during module initialization: " + exception.Message, "Patent Office Tools");
            }
        }
        public List <PurchasingEmployee> ListEmployees()
        {
            using (var context = new ToolsContext())
            {
                var data = from employee in context.Employees
                           orderby employee.LastName
                           select new PurchasingEmployee()
                {
                    ID   = employee.EmployeeID,
                    Name = employee.FirstName + ", " + employee.LastName
                };

                return(data.ToList());
            }
        }