コード例 #1
0
        /// <summary>
        /// Convert StockAlert Object into StockAlert Entity
        /// </summary>
        ///<param name="model">StockAlert</param>
        ///<param name="StockAlertEntity">DataAccess.StockAlert</param>
        ///<returns>DataAccess.StockAlert</returns>
        public static DataAccess.StockAlert ToEntity(
            this StockAlertViewModel model,
            DataAccess.StockAlert entity)
        {
            if (entity.Id == 0)
            {
                entity.Email = model.Email;
            }
            else
            {
                entity.IsActive         = model.IsActive;
                entity.UpdatedTimestamp = DateTime.Now;
            }

            entity.ProductId   = model.ProductId;
            entity.IsAlertSent = model.IsAlertSent;

            if (!String.IsNullOrEmpty(model.SessionUserId))
            {
                entity.UserId = model.SessionUserId;
            }

            if (model.ProductSizeId != 0)
            {
                entity.ProductSizeId = model.ProductSizeId;
            }

            return(entity);
        }
コード例 #2
0
        public IActionResult Index()
        {
            int count = 0;
            List <StockAlertViewModel> lstData = new List <StockAlertViewModel>();

            using (var command = _context.Database.GetDbConnection().CreateCommand())
            {
                command.CommandText = "SELECT p.ProdId as ProductID,p.ProdName as ProductName,ps.Quantity from Product p inner join Stock ps on p.ProdId=ps.ProdId where Quantity < 10";
                _context.Database.OpenConnection();

                using (var result = command.ExecuteReader())
                {
                    StockAlertViewModel data;
                    while (result.Read())
                    {
                        count            = count + 1;
                        data             = new StockAlertViewModel();
                        data.ProductID   = result.GetInt32(0);
                        data.ProductName = result.GetString(1);
                        data.Quantity    = result.GetInt32(2);
                        lstData.Add(data);
                    }
                }
            }
            if (count > 0)
            {
                return(View(lstData));
            }
            else
            {
                return(null);
            }
        }