示例#1
0
        public DataTable Import(StockDTO stockDTO)
        {
            DataTable dtStock = new DataTable();

            con.Open();
            string        GetDrID   = string.Format("SELECT MAX(DressID) AS DressID from dress");
            SqlCommand    GetIDcomd = new SqlCommand(GetDrID, con);
            SqlDataReader rd        = GetIDcomd.ExecuteReader();

            rd.Read();
            int DrID = Convert.ToInt32(rd["DressID"].ToString());

            string SQL = string.Format("Insert into Stock values ({0},{1},SYSDATETIME())",
                                       DrID, stockDTO.DressQuant);

            con.Close();
            con.Open();
            SqlCommand cmd = new SqlCommand(SQL, con);

            SqlDataAdapter adt = new SqlDataAdapter(cmd);

            adt.Fill(dtStock);

            con.Close();
            return(dtStock);
        }
示例#2
0
        public List <StockDTO> getStock(int atmID)
        {
            List <StockDTO> lstStock = new List <StockDTO>();

            try
            {
                string     queryString = "SELECT * FROM Stock WHERE ATMID=@atmID";
                SqlCommand cmd         = new SqlCommand(queryString, DataConnection.connect);
                cmd.Parameters.AddWithValue("atmID", atmID);
                SqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    StockDTO stock = new StockDTO(int.Parse(dr["StockID"].ToString()),
                                                  int.Parse(dr["ATMID"].ToString()),
                                                  int.Parse(dr["MoneyID"].ToString()),
                                                  0);
                    lstStock.Add(stock);
                }
                dr.Close();
                DataConnection.closeConnection();
            }
            catch (Exception)
            {
                DataConnection.closeConnection();
                return(null);
            }
            return(lstStock);
        }
        public ActionResult Create(StockVm model)
        {
            //check if Model state is valid then return
            if (!ModelState.IsValid)
            {
                return(View(model)); //this model will af=gain dislay in the input form
            }

            //copy from view model to DTO
            StockDTO dto = new StockDTO()
            {
                Name        = model.Name,
                Description = model.Description,
                Price       = model.Price,
                Quantity    = model.Quantity
            };

            using (Db db = new Db())
            {
                var cat = db.categories.Find(model.CategoryId);
                dto.Category = cat;

                db.Products.Add(dto);
                db.SaveChanges();
            }

            TempData["cnf"] = "You have added a new item in stock";
            return(RedirectToAction("index"));
        }
示例#4
0
        public void ConvertToDTO(ProductDTO toDTO)
        {
            toDTO.Name  = Name;
            toDTO.Price = Price;
            toDTO.Id    = Id;
            toDTO.Sku   = Sku;

            toDTO.Stocks.Clear();
            foreach (Stock stock in Stocks)
            {
                StockDTO newStockDTO = new StockDTO();
                stock.ConvertToDTO(newStockDTO);

                toDTO.Stocks.Add(newStockDTO);
            }

            toDTO.Tags.Clear();
            foreach (Tag tag in Tags)
            {
                TagDTO newTagDTO = new TagDTO();
                tag.ConvertToDTO(newTagDTO);

                toDTO.Tags.Add(newTagDTO);
            }
        }
示例#5
0
        public int GetNumberOfMoney(int moneyValue)
        {
            StockDTO stock = new StockDTO();

            stock = stockDAL.GetNumberOfMoney(moneyValue);
            return(stock.Quantity);
        }
 private void AddItem()
 {
     try
     {
         if (!txtItemID.Text.Trim().Equals(string.Empty))
         {
             StockDTO oStockDTO = new StockDTO();
             oStockDTO.itemID    = txtItemID.Text.Trim();
             oStockDTO.Oilseal   = txtOilSeal.Text.Trim();
             oStockDTO.Quntity   = Convert.ToInt32(txtQuntity.Text.Trim());
             oStockDTO.StausCode = txtStatusCod.Text.Trim();
             oStockDTO.Supplier  = txtSupplir.Text.Trim();
             if (oStockBL.InsertItem(oStockDTO))
             {
                 ClearControls();
                 MessageBox.Show("Item inserted successfully.!");
             }
         }
         else
         {
             txtItemID.Focus();
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        async Task <IStockDTO> IRequestHandler <StockUpdateService, IStockDTO> .Handle(StockUpdateService request, CancellationToken cancellationToken)
        {
            try
            {
                var client = bus.CreateRequestClient <StockRequest>(new Uri("queue:stock-update-queue"));

                //var response = await client.GetResponse<IStockDTO>(mapper.Map<StockDTO>(request));
                var response = await client.GetResponse <StockResponse>(new StockRequest()
                {
                    ProductName = request.Stock.ProductName,
                    Quantity    = request.Stock.Quantity
                });

                var stockDTO = new StockDTO()
                {
                    ProductName   = response.Message.ProductName,
                    Quantity      = response.Message.Quantity,
                    Status        = response.Message.Status,
                    StockIdentity = response.Message.StockIdentity
                };

                return(stockDTO);
            }
            catch
            {
                throw;
            }
        }
        async Task <SagaContext <SagaData> > ISagaStart <SagaData> .HandleAsync(SagaContext <SagaData> sagaContext)
        {
            try
            {
                IStockDTO stockDTO = new StockDTO()
                {
                    ProductName = sagaContext?.Data?.SalesOrder?.ProductName,
                    Quantity    = sagaContext?.Data?.SalesOrder?.OrderQty
                };

                //var result = await mediator.Send<IStockDTO>(mapper.Map<StockUpdateService>(stockDTO));

                var result = await mediator.Send <IStockDTO>(new StockUpdateService()
                {
                    Stock = stockDTO
                });

                sagaContext.Data.Stock = result;
            }
            catch (Exception ex)
            {
                sagaContext.Error = ex;
            }

            return(sagaContext);
        }
示例#9
0
 public StockDTO getStock(int atmID, int moneyID)
 {
     try
     {
         StockDTO   stock       = null;
         string     queryString = "SELECT * FROM Stock WHERE ATMID=@atmID AND MoneyID=@moneyID";
         SqlCommand cmd         = new SqlCommand(queryString, DataConnection.connect);
         cmd.Parameters.AddWithValue("atmID", atmID);
         cmd.Parameters.AddWithValue("moneyID", moneyID);
         SqlDataReader dr = cmd.ExecuteReader();
         if (dr.Read())
         {
             stock = new StockDTO(int.Parse(dr["StockID"].ToString()),
                                  int.Parse(dr["ATMID"].ToString()),
                                  int.Parse(dr["MoneyID"].ToString()),
                                  int.Parse(dr["Quantity"].ToString())
                                  );
         }
         dr.Close();
         DataConnection.closeConnection();
         return(stock);
     }
     catch (Exception)
     {
         DataConnection.closeConnection();
         return(null);
     }
 }
示例#10
0
        public ResultBM UpdateStock(StockBM stockBm)
        {
            try
            {
                StockDAL stockDal         = new StockDAL();
                StockDTO stockDto         = null;
                ResultBM validationResult = IsValid(stockBm);

                if (!validationResult.IsValid())
                {
                    return(validationResult);
                }
                stockDto = new StockDTO(stockBm.id, stockBm.Name, stockBm.Quantity, stockBm.itemType.id, stockBm.donation.id, stockBm.depot.id, stockBm.DueDate, stockBm.Location);

                stockDal.UpdateStock(stockDto);

                new DonationBLL().UpdateToStoredStatusIfApply(stockBm.donation.id);

                return(new ResultBM(ResultBM.Type.OK, "Se ha creado el stock.", stockBm));
            }
            catch (Exception exception)
            {
                return(new ResultBM(ResultBM.Type.EXCEPTION, SessionHelper.GetTranslation("UPDATING_ERROR") + " " + exception.Message, exception));
            }
        }
示例#11
0
 public List <StockDTO> GetListStock()
 {
     try
     {
         conn.Open();
         List <StockDTO> list  = new List <StockDTO>();
         string          query = "SELECT * FROM tblStock";
         SqlCommand      cmd   = new SqlCommand(query, conn);
         SqlDataReader   dr    = cmd.ExecuteReader();
         while (dr.Read())
         {
             StockDTO stock = new StockDTO(
                 int.Parse(dr["StockID"].ToString()),
                 int.Parse(dr["MoneyID"].ToString()),
                 int.Parse(dr["ATMID"].ToString()),
                 int.Parse(dr["Quantity"].ToString()));
             list.Add(stock);
         }
         conn.Close();
         return(list);
     }
     catch (Exception)
     {
         return(null);
     }
 }
 public static StockRequestModel StockDTOToStockRequestModel(StockDTO stock)
 {
     return(new StockRequestModel(stock.Id, stock.ProductId, stock.Amount, stock.Date)
     {
         Product = stock.Product != null?ProductRequestChildModel.ProductDTOToProductRequestChildModel(stock.Product) : null,
     });
 }
示例#13
0
        public StockDTO GetNumberOfMoney(int moneyValue)
        {
            try
            {
                conn.Open();
                switch (moneyValue)
                {
                case 20: moneyValue = 1; break;

                case 50: moneyValue = 2; break;

                case 100: moneyValue = 3; break;

                case 200: moneyValue = 4; break;

                case 500: moneyValue = 5; break;
                }
                string     query = "SELECT Quantity FROM tblStock WHERE MoneyID=@id";
                SqlCommand cmd   = new SqlCommand(query, conn);
                cmd.Parameters.AddWithValue("id", moneyValue);
                SqlDataReader dr = cmd.ExecuteReader();
                if (dr.Read())
                {
                    StockDTO stock = new StockDTO(int.Parse(dr["Quantity"].ToString()));
                    conn.Close();
                    return(stock);
                }
                conn.Close();
                return(null);
            }
            catch (Exception)
            {
                return(null);
            }
        }
示例#14
0
        StockDTO IStockFunctions.CreateStock(StockDTO stock)
        {
            StockDTO newStock = stock;
            string   command  = "INSERT INTO Stock (Quantity,Description,ProductId) OUTPUT INSERTED.Id VALUES(@SQuantity,@SDesc,@SProductId)";

            using (SqlConnection sqlconnection = new SqlConnection(connectionstring))
            {
                sqlconnection.Open();
                using (SqlCommand cmd = new SqlCommand(command, sqlconnection))
                {
                    cmd.Parameters.Add("@SQuantity", System.Data.SqlDbType.Int).Value  = newStock.Quantity;
                    cmd.Parameters.Add("@SDesc", System.Data.SqlDbType.NVarChar).Value = newStock.Description;
                    cmd.Parameters.Add("@SProductId", System.Data.SqlDbType.Int).Value = newStock.ProductId;

                    var reader = cmd.ExecuteReader();

                    if (reader.Read())
                    {
                        newStock = new StockDTO()
                        {
                            Id          = reader.GetInt32(0),
                            Quantity    = stock.Quantity,
                            Description = stock.Description,
                            ProductId   = stock.ProductId
                        };
                    }
                }
            }
            return(newStock);
        }
        public async Task <IActionResult> PutStock(int id, StockDTO stockDTO)
        {
            if (id != stockDTO.ID)
            {
                return(BadRequest());
            }

            _context.Entry(stockDTO).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!StockExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
示例#16
0
        //DELETE api/stocks/id
        public void Delete(StockDTO stock)
        {
            //Need to have error handling!
            var stockToDelete = stockRepo.GetById(stock.StockReferenceID);

            stockRepo.Delete(stockToDelete);
        }
示例#17
0
        public async Task <ActionResult> Create(StockViewModel stockView)
        {
            StockDTO stockDTO = Mapper.Map <StockDTO>(stockView);

            await stockService.CreateAsync(stockDTO);

            return(RedirectToAction("Index"));
        }
        public bool Modify([FromBody] StockRequestModel stock)
        {
            ProductDTO product  = this.productsFacade.Get(stock.ProductId);
            StockDTO   stockDto = StockRequestModel.StockRequestModelToStockDTO(stock);

            stockDto.Product = product;
            return(stocksFacade.Modify(stockDto));
        }
示例#19
0
 private Stock updateStock(StockDTO stock, Stock stockToUpdate)
 {
     stockToUpdate.IssueID      = stock.IssueID;
     stockToUpdate.Condition    = stock.Condition;
     stockToUpdate.AvailableQty = stock.AvailableQuantity;
     stockToUpdate.Price        = stock.Price;
     return(stockToUpdate);
 }
示例#20
0
 public StockOut(StockDTO stockDTO)
 {
     ID                = stockDTO.ID;
     ProductID         = stockDTO.ProductID;
     TotalQuantity     = stockDTO.TotalQuantity;
     AvailableQuantity = stockDTO.AvailableQuantity;
     Product           = stockDTO.Product;
 }
示例#21
0
        public async Task <ActionResult> Search(StockDTO searchModel)
        {
            var result = await this.Mediator.Send(new GetStocksQuery
            {
                SearchModel = searchModel ?? new StockDTO()
            });

            return(ResponseHelper.ResponseOutcome <StockDTO>(result, this));
        }
示例#22
0
        public async Task <ActionResult> Update(StockDTO data)
        {
            var result = await this.Mediator.Send(new UpdateStockCommand
            {
                Data = data
            });

            return(ResponseHelper.ResponseOutcome <StockDTO>(result, this));
        }
示例#23
0
        //PUT api/stocks
        public StockDTO Put(StockDTO stock)
        {
            //Need to have error handling!
            Stock stockToGet    = stockRepo.GetById(stock.StockReferenceID);
            var   stockToUpdate = updateStock(stock, stockToGet);

            stockRepo.Update(stockToUpdate);
            return(stock);
        }
        public async Task <ActionResult <StockOut> > PostStock([FromForm] StockIn stockIn)
        {
            var stockDto = new StockDTO(stockIn);

            _context.Stocks.Add(stockDto);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetStock", new { id = stockDto.ID }, stockDto));
        }
        public StockRequestModel Add([FromBody] StockNewRequestModel stock)
        {
            ProductDTO product  = this.productsFacade.Get(stock.ProductId);
            StockDTO   stockDto = StockNewRequestModel.StockNewRequestModelToStockDTO(stock);

            stockDto.Product = product;
            return(StockRequestModel.StockDTOToStockRequestModel(
                       stocksFacade.Add(stockDto)));
        }
示例#26
0
        private void btnImport_Click(object sender, EventArgs e)
        {
            DressDTO dressDTO = new DressDTO(txtDressName.Text, txtDressDesc.Text, int.Parse(txtPriceDress.Text));
            StockDTO stockDTO = new StockDTO(Convert.ToInt32(quantity.Value));

            dressBUS.InsertDress(dressDTO);
            stockBUS.Import(stockDTO);
            DressManagement_Load(sender, e);
        }
示例#27
0
        public void CalculatePriceChange(int stockId, StatisticsDTO statistics)
        {
            decimal  newPrice = _transactionService.GetAll(statistics).Where(item => item.StockId == stockId).TakeLast(100).Average(s => s.Price);
            StockDTO stock    = _stockService.GetStockById(stockId, statistics);

            stock.PriceDelta   = ((stock.CurrentPrice / newPrice) * 100) - 100;
            stock.CurrentPrice = newPrice;

            _stockService.EditStock(stockId, stock, statistics);
        }
示例#28
0
 public StockVm(StockDTO row)
 {
     this.Id           = row.Id;
     this.Name         = row.Name;
     this.Description  = row.Description;
     this.Price        = row.Price;
     this.Quantity     = row.Quantity;
     this.CategoryId   = row.Category.Id;
     this.CategoryName = row.Category.Categoryname;
 }
示例#29
0
        public ResultBM GetStock(int stockId)
        {
            try {
                DonationBLL donationBll    = new DonationBLL();
                ResultBM    donationResult = null;
                DepotBLL    depotBll       = new DepotBLL();
                ResultBM    depotResult    = null;
                ItemTypeBLL itemTypeBll    = new ItemTypeBLL();
                ResultBM    itemTypeResult = null;
                StockDAL    stockDal       = new StockDAL();
                StockBM     stockBm        = null;
                StockDTO    stockDto       = stockDal.GetStock(stockId);

                //Si existe el stock, las relaciones deberían existir... TODAS
                if (stockDto != null)
                {
                    donationResult = donationBll.GetDonation(stockDto.donationId);
                    if (!donationResult.IsValid())
                    {
                        return(donationResult);
                    }
                    if (donationResult.GetValue() == null)
                    {
                        throw new Exception(SessionHelper.GetTranslation("RETRIEVING_ERROR") + " donationId " + stockDto.donationId);
                    }

                    depotResult = depotBll.GetDepot(stockDto.depotId);
                    if (!depotResult.IsValid())
                    {
                        return(depotResult);
                    }
                    if (depotResult.GetValue() == null)
                    {
                        throw new Exception(SessionHelper.GetTranslation("RETRIEVING_ERROR") + " depotId " + stockDto.depotId);
                    }

                    itemTypeResult = itemTypeBll.GetItemType(stockDto.itemTypeId);
                    if (!itemTypeResult.IsValid())
                    {
                        return(itemTypeResult);
                    }
                    if (itemTypeResult.GetValue() == null)
                    {
                        throw new Exception(SessionHelper.GetTranslation("RETRIEVING_ERROR") + " itemTypeId " + stockDto.itemTypeId);
                    }

                    stockBm = new StockBM(stockDto, donationResult.GetValue <DonationBM>(), depotResult.GetValue <DepotBM>(), itemTypeResult.GetValue <ItemTypeBM>());
                }

                return(new ResultBM(ResultBM.Type.OK, "Operación exitosa.", stockBm));
            }
            catch (Exception exception) {
                return(new ResultBM(ResultBM.Type.EXCEPTION, SessionHelper.GetTranslation("RETRIEVING_ERROR") + " " + exception.Message, exception));
            }
        }
示例#30
0
        Task <IStockDTO> IRequestHandler <StockUpdateRepository, IStockDTO> .Handle(StockUpdateRepository request, CancellationToken cancellationToken)
        {
            try
            {
                var dynamicParameterTask = base.SetParameterAsync("Stock-Update", request);

                var result =
                    sqlClientDbProvider
                    ?.DapperBuilder
                    ?.OpenConnection(sqlClientDbProvider.GetConnection())
                    ?.Parameter(async() => await dynamicParameterTask)
                    ?.Command(async(dbConnection, dynamicParameter) =>
                {
                    StockDTO stockDTO = null;

                    try
                    {
                        var sqlGrid =
                            await
                            dbConnection
                            ?.QueryMultipleAsync(sql: "uspSetStock", param: dynamicParameter, commandType: CommandType.StoredProcedure);

                        var message = sqlGrid.ReadFirst();

                        if (message.Message == "Quantity available")
                        {
                            stockDTO          = sqlGrid.ReadFirstOrDefault <StockDTO>();
                            stockDTO.Quantity = request?.Quantity;
                            stockDTO.Status   = message.Message;
                        }
                        else
                        {
                            stockDTO = new StockDTO()
                            {
                                Status = message.Message
                            };
                        }

                        return(stockDTO);
                    }
                    catch
                    {
                        throw;
                    }
                })

                    ?.ResultAsync <IStockDTO>();

                return(result);
            }
            catch
            {
                throw;
            }
        }