public JsonResult AddStock(AddStockModel model)
        {
            int    tipo    = 0;
            string mensaje = "";

            if (!ModelState.IsValid)
            {
                //Extrae el primer mensaje de error que tenga el modelo
                mensaje = ModelState.Values.Select(e => e.Errors).Where(e => e.Count > 0).FirstOrDefault().Select(v => v.ErrorMessage).FirstOrDefault();
            }
            else
            {
                using (var db = new VentaArticulosCreditoEntities())
                {
                    var stock = new Inventario(model.articulo, model.precioCompra, model.precioVenta, model.cantidad, model.fecha);

                    db.Inventario.Add(stock);
                    db.SaveChanges();
                    tipo    = 1;
                    mensaje = "Stock agregado correctamente";
                }
            }

            return(Json(new { tipo = tipo, mensaje = mensaje }, JsonRequestBehavior.AllowGet));
        }
示例#2
0
        public async Task addStockToProductOption(AddStockModel addStockModel)
        {
            var productOption = await appDb.ProductOptions.FindAsync(addStockModel.OptionId, addStockModel.ProductId);

            productOption.ProductStock = addStockModel.Stock;

            await appDb.SaveChangesAsync();
        }
示例#3
0
        public async Task <IActionResult> AddStockToProductOption([FromBody] AddStockModel addStockModel)
        {
            await productServices.addStockToProductOption(addStockModel);

            return(Ok(new ProductResponse
            {
                Message = "Succesfully added stock"
            }));
        }
示例#4
0
        public SuccessOrFailure Add([FromBody] AddStockModel addstock)
        {
            Boolean canAdd = false;

            // get user based on email and password
            if (addstock.SessionKey.Length <= 0)
            {
                return(new SuccessOrFailure()
                {
                    Success = false,
                    Message = "Invalid Session Key",
                });
            }

            _connection.Open();
            SqlCommand select_command = new SqlCommand("Select id, email, session_key from [user] where session_key like @session_key", _connection);

            select_command.Parameters.AddWithValue("@session_key", addstock.SessionKey);
            using (SqlDataReader select_reader = select_command.ExecuteReader())
            {
                if (select_reader.Read())
                {
                    if (select_reader.HasRows)
                    {
                        canAdd = true;
                    }
                }
            }

            // check user access
            if (!canAdd)
            {
                return(new SuccessOrFailure()
                {
                    Success = true,
                    Message = "You cannot add stock with this user"
                });
            }
            // store stock into DB
            SqlCommand insert_command = new SqlCommand("INSERT INTO [dbo].[stock] ([reg_no] ,[make] ,[model] ,[model_year] ,[kms] ,[colour] ,[vin] ,[retail_price] ,[cost_price] ,[DTCreated] ,[DTUpdated]) VALUES ( @reg_no, @make, @model, @model_year, @kms, @colour, @vin, @retail_price, @cost_price, @DTCreated, @DTUpdated); SELECT SCOPE_IDENTITY() AS ID; ", _connection);

            insert_command.Parameters.AddWithValue("@reg_no", addstock.Stock.RegNumber);
            insert_command.Parameters.AddWithValue("@make", addstock.Stock.Make);
            insert_command.Parameters.AddWithValue("@model", addstock.Stock.Model);
            insert_command.Parameters.AddWithValue("@model_year", addstock.Stock.ModelYear);
            insert_command.Parameters.AddWithValue("@kms", addstock.Stock.KMS);
            insert_command.Parameters.AddWithValue("@colour", addstock.Stock.Colour);
            insert_command.Parameters.AddWithValue("@vin", addstock.Stock.VIN);
            insert_command.Parameters.AddWithValue("@retail_price", addstock.Stock.RetailPrice);
            insert_command.Parameters.AddWithValue("@cost_price", addstock.Stock.CostPrice);
            insert_command.Parameters.AddWithValue("@DTCreated", DateTime.Now);
            insert_command.Parameters.AddWithValue("@DTUpdated", DateTime.Now);
            insert_command.CommandType = CommandType.Text;
            addstock.Stock.ID          = Convert.ToInt32(insert_command.ExecuteScalar());

            foreach (var image in addstock.Stock.Images)
            {
                SqlCommand insert_image_command = new SqlCommand("INSERT INTO [dbo].[images] ([name] ,[data] ,[stock_id]) output INSERTED.ID VALUES (@name ,@data ,@stockID)", _connection);
                insert_image_command.Parameters.AddWithValue("@name", image.Name);
                insert_image_command.Parameters.AddWithValue("@data", image.Data);
                insert_image_command.Parameters.AddWithValue("@stockID", addstock.Stock.ID);
                insert_image_command.CommandType = CommandType.Text;
                insert_image_command.ExecuteNonQuery();
            }
            foreach (var accessory in addstock.Stock.Accessories)
            {
                SqlCommand insert_image_command = new SqlCommand("INSERT INTO [dbo].[accessory] ([name] ,[description] ,[stock_id]) VALUES (@name ,@description ,@stockID)", _connection);
                insert_image_command.Parameters.AddWithValue("@name", accessory.Name);
                insert_image_command.Parameters.AddWithValue("@description", accessory.Description);
                insert_image_command.Parameters.AddWithValue("@stockID", addstock.Stock.ID);
                insert_image_command.CommandType = CommandType.Text;
                insert_image_command.ExecuteNonQuery();
            }
            _connection.Close();
            return(new SuccessOrFailure()
            {
                Success = true,
                Message = "Stock Added Suiccesfully"
            });
        }