Пример #1
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Product = await _context.Products.FirstOrDefaultAsync(m => m.Product_ID == id);

            Categories               = _context.Categories.ToList();
            StockItems               = _context.Stock.ToList();
            stockToProducts          = _context.StockToProducts.Where(stp => stp.ProductId == id).ToList();
            StockToProductStockItems = new List <StockToProduct_StockItems>();
            foreach (var stp in stockToProducts)
            {
                StockToProduct_StockItems stp_si = new StockToProduct_StockItems
                {
                    StockName = StockItems.FirstOrDefault(si => si.Id == stp.StockId).StockName,
                    Quantity  = stp.QuantityUse
                };
                StockToProductStockItems.Add(stp_si);
            }
            if (Product == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Пример #2
0
        private void LoadSearchResults()
        {
            PerformAction(async() =>
            {
                try
                {
                    _isSearchInProgress = true;
                    var stockItems      = await _stockBussinessLogic.SearchStockItems(SearchText,
                                                                                      _searchPageIndex);
                    if (stockItems != null && stockItems.Count > 0)
                    {
                        if (_searchPageIndex == 1)
                        {
                            StockItems.Clear();
                        }

                        var tempStockItems = new ObservableCollection <StockModel>();
                        foreach (var stockItem in stockItems)
                        {
                            tempStockItems.Add(stockItem);
                        }

                        StockItems        = new ObservableCollection <StockModel>(StockItems.Concat(tempStockItems));
                        SelectedStockItem = StockItems.FirstOrDefault();
                    }
                }
                finally
                {
                    _tracker.Stop();
                    Log.Info(string.Format("Time taken by stock search is {0}ms", _tracker.Elapsed.TotalMilliseconds));
                    SearchText = string.Empty;
                }
            }, SearchTextFieldName);
        }
Пример #3
0
        /// <summary>
        /// Loads the view-model.
        /// </summary>
        /// <returns>The async.</returns>
        /// <param name="parameters">Parameters.</param>
        protected override async Task LoadAsync(IDictionary <string, object> parameters)
        {
            try
            {
                InProgress = true;

                // reset the list everytime we load the page
                StockItems.Clear();

                var stockItems = await _stocklistWebServiceController.GetAllStockItems();

                // for all contracts build stock item view model and add to the observable collection
                foreach (var model in stockItems.Select(x =>
                {
                    var model = _stockItemFactory();
                    model.Apply(x);
                    return(model);
                }))
                {
                    StockItems.Add(model);
                }

                InProgress = false;
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e);
            }
        }
Пример #4
0
        public RetrieveItems()
        {
            StreamReader reader;
            FileStream   fs = new FileStream(@"items.txt", FileMode.Open, FileAccess.Read);

            reader = new StreamReader(fs);
            try
            {
                string[] iteminfo;
                while (!reader.EndOfStream)
                {
                    iteminfo = reader.ReadLine().Split(' ');
                    StockItems newitem = new StockItems
                    {
                        item_name            = iteminfo[0].ToLower(),
                        item_price           = Convert.ToDouble(iteminfo[1]),
                        item_stock           = Convert.ToInt32(iteminfo[2]),
                        item_stock_threshold = Convert.ToInt32(iteminfo[3])
                    };
                    _itemsList.Add(newitem);
                }
            }
            finally
            {
                reader.Dispose();
            }
        }
Пример #5
0
        public void Start()
        {
            Items = GetItems();

            foreach (var item in Items)
            {
                if (item is DividendTransactionDto dividend)
                {
                    ImportDividend(dividend);
                }
                else if (item is SellingTransactionDto selling)
                {
                    ImportSelling(selling);
                }
                else
                {
                    ImportBuying(item as BuyingTransactionDto);
                }

                if (item.OldId == 2201)
                {
                    //Splits
                    ImportSplit(DateTime.Parse("2012-05-16 00:00:00"), StockItems.FirstOrDefault(s => s.Wkn.Equals("548851")), 500, 1.991m); //Pferdewetten
                }

                if (item.OldId == 2184)
                {
                    //Splits
                    ImportSplit(DateTime.Parse("2012-12-13 00:00:00"), StockItems.FirstOrDefault(s => s.Wkn.Equals("A0YJT2")), 137, 13.209124m); //Lambda TD Software
                }
            }
        }
Пример #6
0
        public void AddItemToStock(int stockId, StockItems item)
        {
            var stock = _stock.GetById(stockId);

            if (stock != null)
            {
                item.StockId     = stockId;
                item.DateCreated = DateTime.Now;
                _stockItems.Save(item);
            }
        }
Пример #7
0
        public void RemoveStock(int stockId)
        {
            var str = StockItems.Single(i => i.StockId == stockId);

            str.InvoiceStatusId = (int)InvoiceStatusEnum.Pending;
            StockItems.Remove(str);
            FreightApportionment = CalculateFreightApportionment();
            if (StockItems.Count == 0)
            {
                Invoice.Items.Remove(this);
            }
        }
Пример #8
0
        private void ShowButton_Click(object sender, EventArgs e)
        {
            int storeId = Conversion.TryCastInteger(this.storeHiddenField.Value);

            if (storeId.Equals(0))
            {
                return;
            }


            this.grid.DataSource = StockItems.ListClosingStock(AppUsers.GetCurrentUserDB(), storeId);
            this.grid.DataBind();
        }
Пример #9
0
        public StockItems GetStockDetails(int restaurantID, int menuID)
        {
            TblMenu StockQuantity = search_Repository.GetStockDetails(restaurantID, menuID);

            StockItems stockItem = new StockItems()
            {
                Item         = StockQuantity.Item,
                RestaurantID = restaurantID,
                MenuId       = StockQuantity.Id,
                Quantity     = StockQuantity.quantity
            };


            return(stockItem);
        }
Пример #10
0
        private ITransactionDto ImportDividend(IDataRecord reader)
        {
            var item = new DividendTransactionDto();

            var dividendStock = StockItems[int.Parse(reader["Stock_ID"].ToString())];

            item.OldId           = int.Parse(reader["ID"].ToString());
            item.Shares          = decimal.Parse(reader["Units"].ToString());
            item.Description     = reader["Description"].ToString();
            item.OrderCosts      = decimal.Parse(reader["OrderCosts"].ToString());
            item.OrderDate       = DateTime.Parse(reader["OrderDate"].ToString());
            item.OriginalVersion = -1;
            item.PricePerShare   = decimal.Parse(reader["PricePerUnit"].ToString());
            item.Stock           = StockItems.FirstOrDefault(s => s.Value.Wkn.Equals(dividendStock.Wkn) && s.Value.OldId != dividendStock.OldId).Value;
            item.Tag             = reader["Tag"].ToString();
            item.Taxes           = decimal.Parse(reader["Taxes"].ToString());
            item.Image           = ImportImage(item.Id, item.OldId);

            //Import
            var cmd = new TransactionDividendCommand(
                item.Id,
                -1,
                item.OrderDate,
                item.Shares,
                item.PricePerShare,
                item.OrderCosts,
                item.Description,
                item.Tag,
                null,
                item.Stock.Id,
                item.Taxes);

            CommandDispatcher.Execute(cmd);

            //Image
            if (item.Image != null)
            {
                LoggingService.Info($"Dividend {item.Stock.Name} ({item.Shares} x {item.PricePerShare}) + IMAGE");
            }
            else
            {
                LoggingService.Info($"Dividend {item.Stock.Name} ({item.Shares} x {item.PricePerShare})");
            }

            return(item);
        }
Пример #11
0
        public void UpdateStockItem(StockItems StockItems)
        {
            var DBrecord = _context.StockItems.Find(StockItems.Id);

            if (StockItems != null)
            {
                DBrecord.ItemName    = StockItems.ItemName == null || StockItems.ItemName == "" ? DBrecord.ItemName : StockItems.ItemName;
                DBrecord.Description = StockItems.Description == null || StockItems.Description == "" ? DBrecord.Description : StockItems.Description;
                DBrecord.Quantity    = StockItems.Quantity;
            }
            try
            {
                _context.SaveChanges();
            }
            catch (Exception e)
            {
                var errorMsg = e.ToString();
            }
        }
Пример #12
0
        async Task ProcessMessagesAsync(Message message, CancellationToken token)
        {
            string msg = Encoding.UTF8.GetString(message.Body);

            var        stockEntity = JsonConvert.DeserializeObject <StockItems>(Encoding.UTF8.GetString(message.Body));
            StockItems cart        = new StockItems
            {
                RestaurantId = stockEntity.RestaurantId,
                MenuId       = stockEntity.MenuId,
                CustomerId   = stockEntity.CustomerId
            };

            _restaurantBusiness.ItemInStock(cart.RestaurantId, cart.MenuId, cart.CustomerId);


            await _subscriptionClient.CompleteAsync(message.SystemProperties.LockToken);

            await _subscriptionClient.CloseAsync();
        }
Пример #13
0
        /// <summary>
        /// Gets the stock
        /// </summary>
        /// <returns></returns>
        private StockDto GetStock(int oldId)
        {
            var oldStock = StockItems.FirstOrDefault(s => s.OldId == oldId);

            // We only imported non dividend stocks, so we need to merge this now
            if (oldStock == null)
            {
                var dividendStock = DividendStockItems.FirstOrDefault(s => s.OldId == oldId);

                //Get the corresponding stock with the same WKN as the dividend
                oldStock = StockItems.FirstOrDefault(s => s.Wkn.Equals(dividendStock.Wkn));

                var dividend = (StockDto)oldStock.Clone();
                dividend.IsDividend = true;

                return(dividend);
            }

            return(oldStock);
        }
Пример #14
0
        private void BindGridView()
        {
            DateTime from     = Conversion.TryCastDate(this.fromDateTextBox.Text);
            DateTime to       = Conversion.TryCastDate(this.toDateTextBox.Text);
            int      userId   = AppUsers.GetCurrentLogin().View.UserId.ToInt();
            string   itemCode = this.itemCodeInputText.Value;
            int      storeId  = Conversion.TryCastInteger(this.storeIdHidden.Value);

            if (string.IsNullOrWhiteSpace(itemCode))
            {
                return;
            }

            if (storeId.Equals(0))
            {
                return;
            }

            this.statementGridView.DataSource = StockItems.GetAccountStatement(AppUsers.GetCurrentUserDB(), from, to, userId, itemCode, storeId);
            this.statementGridView.DataBound += this.StatementGridViewDataBound;
            this.statementGridView.DataBind();
        }
Пример #15
0
        /// <summary>
        /// Loads all the Stock items
        /// </summary>
        private void LoadAllStockItems()
        {
            PerformAction(async() =>
            {
                _isSearchInProgress = false;
                var stockItems      = await _stockBussinessLogic.GetStockItems(_allStockItemsPageIndex);
                if (stockItems != null && stockItems.Count > 0)
                {
                    if (_allStockItemsPageIndex == 1)
                    {
                        StockItems.Clear();
                    }

                    var tempStockItems = new ObservableCollection <StockModel>();
                    foreach (var stockItem in stockItems)
                    {
                        tempStockItems.Add(stockItem);
                    }

                    StockItems = new ObservableCollection <StockModel>(StockItems.Concat(tempStockItems));
                }
            }, SearchTextFieldName);
        }
Пример #16
0
        // Use a POST to handle the incoming data
        public void ProcessRequest(HttpContext context)
        {
            //
            StreamWriter   writer         = new StreamWriter(context.Response.OutputStream);
            MobileResponse mobileResponse = new MobileResponse();
            MobileRequest  mobileRequest  = null;

            try
            {
                byte[] key = Convert.FromBase64String("Wmf84Y1KsN1tKvxoGohBMLm/qLzq1HpU0/nsmi215xc=");
                byte[] IV  = Convert.FromBase64String("JI24AwSI+EyB/LR2d+1+Lw==");

                // encrypt it
                StreamReader reader = new StreamReader(context.Request.InputStream);
                // string encoded = reader.ReadToEnd();
                // reader.Close();
                // byte[] encrypted = Convert.FromBase64String(encoded);
                // byte[] decrypted = AES.DecryptBytesFromBytes(encrypted, key, IV);

                DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(MobileRequest));
                // MemoryStream requestStream = new MemoryStream(decrypted);
                // requestStream.Position = 0;

                mobileRequest = (MobileRequest)serializer.ReadObject(context.Request.InputStream);
                if (mobileRequest == null)
                {
                    mobileResponse.Error = "Request is null";
                }
                else
                {
                    User user = ContentManagementSystem.FindUser(mobileRequest.User.Email, mobileRequest.User.Password);

                    if (user == null && mobileRequest.Command == "Register")
                    {
                        if (ContentManagementSystem.AddUser("", "", mobileRequest.User.Email, mobileRequest.User.Password))
                        {
                            mobileResponse.User = ContentManagementSystem.FindUser(mobileRequest.User.Email, mobileRequest.User.Password);
                            Email.TellAdministratorAboutNewUser("", "", mobileRequest.User.Email);
                            MailChimp.ListSubscribe(mobileRequest.User.Email, "", "");
                        }
                        else
                        {
                            mobileResponse.Error = "Bad password";
                        }
                    }
                    else if (user != null)
                    {
                        if (user.Password != mobileRequest.User.Password)
                        {
                            mobileResponse.Error = "Bad password";
                        }
                        else
                        {
                            mobileResponse.User     = user;
                            mobileResponse.Contacts = Contact.GetAll();
                            string file     = context.Server.MapPath("/data") + "\\BGA.xls";
                            string backFile = context.Server.MapPath("/data") + "\\Orders.xls";
                            mobileResponse.StockItems = StockItems.Read(file, mobileResponse.User.Price);
                            mobileResponse.BackItems  = OrderItems.Read(backFile, mobileResponse.User, false);

                            string       menustring = @"{""Types"": [
 {""Name"": ""Construction Timber"", ""Id"": ""Construction"", ""Categories"" :
     [
        {""Name"": ""Structural Framing"", ""Id"": ""Structural Framing""},
        {""Name"": ""Strapping"", ""Id"": ""Strapping""},
        {""Name"": ""Cavity Batten"", ""Id"": ""Cavity Batten""}
     ]
 },
 {""Name"": ""Outdoor Timber"", ""Id"": ""Outdoor"", ""Categories"":
     [
      {""Id"": ""Decking/ PremiumBalustrades"", ""Name"": ""Decking (Merchant Grade;Premium)""},
      {""Id"": ""Fencing"", ""Name"": ""Fencing (Palings; Rails; Posts)""},
      {""Id"": ""Landscaping"", ""Name"": ""Landscaping""},
      {""Id"": ""Merch/Sawn/D4S"", ""Name"": ""Merchant Sawn D4S""},
      {""Id"": ""Stuctural"", ""Name"": ""Structural""}
     ]
 },
 {""Name"": ""Industrial/Boxing"", ""Id"": ""Industrial/ Boxing/ Misc"", ""Categories"":
     [
      {""Name"": ""Industrial/Boxing"", ""Id"": ""Industrial/ Boxing/ Misc""}
     ]
 }
]}";
                            MemoryStream menuStream = new MemoryStream();
                            byte[]       bytes      = new byte[menustring.Length * sizeof(char)];
                            System.Buffer.BlockCopy(menustring.ToCharArray(), 0, bytes, 0, bytes.Length);
                            menuStream.Write(bytes, 0, bytes.Length);
                            menuStream.Seek(0, SeekOrigin.Begin);
                            DataContractJsonSerializer menuSerializer = new DataContractJsonSerializer(typeof(LayoutMenu));
                            mobileResponse.Menu = (LayoutMenu)menuSerializer.ReadObject(menuStream);
                        }
                    }
                    else if (user == null)
                    {
                        mobileResponse.Error = "Unknown user";
                    }
                    else
                    {
                        mobileResponse.Error = "Invalid command";
                    }
                }
            }
            catch (Exception e)
            {
                mobileResponse = new MobileResponse()
                {
                    Error = e.Message
                };
            }
            finally
            {
                DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(MobileResponse));
                serializer.WriteObject(context.Response.OutputStream, mobileResponse);
                writer.Close();
            }
        }
Пример #17
0
        public async Task <IActionResult> OnPostAsync()
        {
            Categories = _context.Categories.Select(n => new SelectListItem
            {
                Value = n.Cat_ID.ToString(),
                Text  = n.CategoryName
            }).ToList();
            StockItems = _context.Stock.ToList();

            //if (!ModelState.IsValid)
            //{
            //    return Page();
            //}

            if (UploadImage != null)
            {
                var fileName = Path.Combine(_hostingEnvironment.WebRootPath, "img", UploadImage.FileName);
                using (var fileStream = new FileStream(fileName, FileMode.Create))
                {
                    await UploadImage.CopyToAsync(fileStream);
                }
                Product.ImageUrl = "\\img\\" + UploadImage.FileName; // Set the file name
            }
            Product.Cat_ID = Convert.ToInt32(SelectedTag);
            decimal stockPrice = 0;

            if (StockItemChecked != null)
            {
                List <decimal> ssqNums = new List <decimal>();
                foreach (string ssq in SelectedStockQuantities)
                {
                    if (ssq != null)
                    {
                        decimal quan = 0m;
                        quan = decimal.Parse(ssq, CultureInfo.InvariantCulture);
                        ssqNums.Add(quan);
                    }
                }
                for (int s = 0; s < StockItemChecked.Count; s++)
                {
                    StockItem stock = new StockItem();
                    stock = StockItems.FirstOrDefault(st => st.StockName == StockItemChecked[s]);
                    decimal productStockPrice = stock.Price * ssqNums[s];
                    stockPrice = stockPrice + productStockPrice;

                    StockToProduct newStockToProduct = new StockToProduct
                    {
                        StockId     = stock.Id,
                        ProductId   = Product.Product_ID,
                        QuantityUse = ssqNums[s]
                    };
                    _context.StockToProducts.Add(newStockToProduct);
                    await _context.SaveChangesAsync();
                }
            }
            Product.CostPrice    = stockPrice;
            Product.ProfitMargin = Product.SellingPrice - stockPrice;
            _context.Products.Update(Product);
            await _context.SaveChangesAsync();

            TempData["StatusMessage"] = "Product " + Product.ProductName + " successfully created.";
            return(RedirectToPage("./ProductIndex"));
        }
Пример #18
0
        public async Task <IActionResult> OnPostAsync()
        {
            StockToProducts = _context.StockToProducts.ToList();
            //Product = _context.Products.FirstOrDefault(m => m.Product_ID == Product.Product_ID);
            AllCategories = _context.Categories.ToList();
            StockItems    = _context.Stock.ToList();
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            try
            {
                string imageurl = Product.ImageUrl;
                if (UploadImage != null)
                {
                    var fileName = Path.Combine(_hostingEnvironment.WebRootPath, "img", UploadImage.FileName);
                    using (var fileStream = new FileStream(fileName, FileMode.Create))
                    {
                        await UploadImage.CopyToAsync(fileStream);
                    }
                    Product.ImageUrl = "\\img\\" + UploadImage.FileName; // Set the file name
                }
                else
                {
                    Product.ImageUrl = imageurl;
                }
                Product.Cat_ID = Convert.ToInt32(SelectedTag);
                decimal stockPrice = 0;
                if (StockItemChecked != null || StockItemChecked.Count > 0)
                {
                    List <decimal> ssqNums = new List <decimal>();
                    foreach (string ssq in SelectedStockQuantities)
                    {
                        if (ssq != null)
                        {
                            decimal quan = 0m;
                            quan = decimal.Parse(ssq, CultureInfo.InvariantCulture);
                            ssqNums.Add(quan);
                        }
                    }
                    for (int s = 0; s < StockItemChecked.Count; s++)
                    {
                        StockItem stock = new StockItem();
                        stock = StockItems.FirstOrDefault(st => st.StockName == StockItemChecked[s]);
                        decimal qty = ssqNums[s];
                        decimal productStockPrice = stock.Price * qty;
                        stockPrice = stockPrice + productStockPrice;
                        StockToProduct stp = new StockToProduct();
                        stp = _context.StockToProducts.FirstOrDefault(st => st.StockId == stock.Id && st.ProductId == Product.Product_ID);
                        if (stp == null)
                        {
                            StockToProduct newStockToProduct = new StockToProduct
                            {
                                StockId     = stock.Id,
                                ProductId   = Product.Product_ID,
                                QuantityUse = ssqNums[s]
                            };
                            _context.StockToProducts.Add(newStockToProduct);
                            await _context.SaveChangesAsync();
                        }
                        else
                        {
                            stp.QuantityUse = ssqNums[s];
                            _context.StockToProducts.Update(stp);
                            await _context.SaveChangesAsync();
                        }
                    }
                }
                Product.CostPrice    = stockPrice;
                Product.ProfitMargin = Product.SellingPrice - stockPrice;
                _context.Products.Update(Product);
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductExists(Product.Product_ID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            TempData["StatusMessage"] = "Product " + Product.ProductName + " successfully edited.";

            return(RedirectToPage("./ProductIndex"));
        }
Пример #19
0
 public async Task Search_Click()
 {
     SelectedStockItems = string.IsNullOrWhiteSpace(SearchText) ? StockItems : await Task.FromResult(StockItems.Where(x => x.Name.ToLower().Contains(SearchText.ToLower())).ToList());
 }
Пример #20
0
        public async Task <IEnumerable <StockItemDisplay> > SearchStock(string searchText)
        {
            SelectedStockItems = await Task.FromResult(StockItems.Where(x => x.Name.ToLower().Contains(searchText.ToLower())).ToList());

            return(SelectedStockItems);
        }
 public void InitializeStockItemTables()
 {
     StockItems = CloudTableClient.GetTableReference(Constants.StorageTableNames.StockItems);
     StockItems.CreateIfNotExists();
 }
Пример #22
0
 public ProductContext(ICacheManager cacheManager)
 {
     _cacheManager          = cacheManager;
     _cacheManager.Products = StockItems.FulFillListofProducts();
 }