Exemplo n.º 1
0
        public WoodFurnitureOrder Create(WoodFurnitureOrder model)
        {
            _ctx.WoodFurnitureOrders.Add(model);

            _ctx.SaveChanges();

            return(model);
        }
Exemplo n.º 2
0
        public bool DeleteItem(WoodFurnitureOrder model)
        {
            try
            {
                var entity = GetById(model.Id);

                _ctx.WoodFurnitureOrders.Remove(entity);
                _ctx.SaveChanges();
            }
            catch
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 3
0
        public WoodFurnitureOrder UpdateItem(WoodFurnitureOrder model)
        {
            var entity = GetById(model.Id);

            entity.Id              = model.Id;
            entity.CustomerId      = model.CustomerId;
            entity.Customer        = model.Customer;
            entity.Date            = model.Date;
            entity.Color           = model.Color;
            entity.FurnitureType   = model.FurnitureType;
            entity.FurnitureTypeId = model.FurnitureTypeId;
            entity.WoodTypeId      = model.WoodTypeId;
            entity.WoodType        = model.WoodType;

            _ctx.SaveChanges();

            return(model);
        }
Exemplo n.º 4
0
        public List <WoodFurnitureOrder> GetItemsByName(string name)
        {
            SqlConnection connection = new SqlConnection(_connectionString);

            List <WoodFurnitureOrder> result = new List <WoodFurnitureOrder>();

            WoodFurnitureOrder FinedItem;

            using (connection)
            {
                connection.Open();

                SqlCommand command = new SqlCommand();

                command.Connection  = connection;
                command.CommandType = CommandType.Text;
                command.CommandText = "SELECT * " +
                                      "FROM WoodPiecesOfFurniture " +
                                      $"WHERE FullName = {name}";


                SqlDataReader reader = command.ExecuteReader();

                while (reader.Read())
                {
                    FinedItem = new WoodFurnitureOrder();

                    FinedItem.Id            = reader.GetInt32(0);
                    FinedItem.PhoneNumber   = reader.GetString(1);
                    FinedItem.FullName      = reader.GetString(2);
                    FinedItem.Date          = reader.GetString(3);
                    FinedItem.FurnitureType = reader.GetString(4);
                    FinedItem.Color         = reader.GetString(5);
                    FinedItem.WoodType      = reader.GetString(6);

                    result.Add(FinedItem);
                }

                reader.Close();
            }

            return(result);
        }
Exemplo n.º 5
0
        public WoodFurnitureOrder Create(WoodFurnitureOrder model)
        {
            SqlConnection connection = new SqlConnection(_connectionString);

            using (connection)
            {
                connection.Open();

                var result = connection.Execute("INSERT INTO WoodPiecesOfFurnitureOrders (FullName, PhoneNumber, Date, FurnitureType, Color, WoodType)" +
                                                $"OUTPUT (Inserted.Id) " +
                                                $"VALUES(\'{model.FullName}\', \'{model.PhoneNumber}\', \'{model.Date}\', \'{model.FurnitureType}\', \'{model.Color}\', \'{model.WoodType}\')");


                var insertedId = Convert.ToInt32(result);

                model.Id = insertedId;

                return(model);
            }
        }
Exemplo n.º 6
0
        public WoodFurnitureOrder GetItemById(int id)
        {
            SqlConnection connection = new SqlConnection(_connectionString);

            WoodFurnitureOrder FinedItem = new WoodFurnitureOrder();

            using (connection)
            {
                connection.Open();

                SqlCommand command = new SqlCommand();

                command.Connection  = connection;
                command.CommandType = CommandType.Text;
                command.CommandText = "SELECT * " +
                                      "FROM WoodPiecesOfFurniture " +
                                      $"WHERE Id = {id}";


                SqlDataReader reader = command.ExecuteReader();

                while (reader.Read())
                {
                    FinedItem.Id            = reader.GetInt32(0);
                    FinedItem.PhoneNumber   = reader.GetString(1);
                    FinedItem.FullName      = reader.GetString(2);
                    FinedItem.Date          = reader.GetString(3);
                    FinedItem.FurnitureType = reader.GetString(4);
                    FinedItem.Color         = reader.GetString(5);
                    FinedItem.WoodType      = reader.GetString(6);
                }

                reader.Close();
            }

            return(FinedItem);
        }
Exemplo n.º 7
0
        public WoodFurnitureOrder Create(WoodFurnitureOrder model)
        {
            SqlConnection connection = new SqlConnection(_connectionString);

            using (connection)
            {
                connection.Open();

                SqlCommand command = new SqlCommand();

                command.Connection  = connection;
                command.CommandType = CommandType.Text;
                command.CommandText = "INSERT INTO WoodPiecesOfFurniture (FullName, PhoneNumber, Date, FurnitureType, Color, WoodType)" +
                                      $"OUTPUT (Inserted.Id) " +
                                      $"VALUES(\'{model.FullName}\', \'{model.PhoneNumber}\', \'{model.Date}\', \'{model.FurnitureType}\', \'{model.Color}\', \'{model.WoodType}\')";


                var insertedId = Convert.ToInt32(command.ExecuteScalar());

                model.Id = insertedId;

                return(model);
            }
        }